User Control Question: Button Onclick Event won't work (won't fire)

Hi all,

I create a webusercontrol and load it to home page dynamicly using Place Holder . However, the Button Onclick Event won't work (won't fire) in my Web user Control.

Here are the codes.


Class test2

Inherits System.Web.UI.UserControl

Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click

End Sub

End Class


I set break point to (Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click). Can anyone tell me whats going wrong with my code? Thanks a lot!

11/12/2006 5:09:44 AM 93655 articles. 6 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 37

First -- is the web control actually showing up in your page? (I gotta assume it is, since you see a button on it to click).

Second -- did you code any method for the btn_Click event?

Third -- what is the ID of the button? Maybe the Handles statement contains a different ID?

Fourth -- When you set the breakpoint on the method signature line, does the program actually break when you click the button?

Visit my blog
11/12/2006 7:32:23 AM


I tried as you described, the following is my code which works fine.  refer to it

my usercontrol

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="uc.ascx.cs" Inherits="uc" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
code behind:

public partial class uc : System.Web.UI.UserControl
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)

my home page:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Src="uc.ascx" TagName="uc" TagPrefix="uc1" %>
<%@ Reference Control ="~/uc.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

code behind

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        uc u = (uc)Page.LoadControl("uc.ascx");

hope it helps


11/13/2006 2:00:35 AM

Similar Artilces:

Dynamic user control's onclick event won't fire
I'm dynamically creating several user controls that get loaded dynamically into a placeholder based on which linkbutton a user clicks, however my linkbutton onclick events never fire off.  I've tried initializing them in the Page_Init, Page_Load, & On_Init however none seemed to work.  If it helps, my placeholder control is located on my masterpage (called "phMenuContent") and I'm using ajax.  Here's my code so far: My user control page: ---------------------------------------------------------------------------------...

Won't send, won't receive, won't do anything but send me rejection messages!
I keep getting messages such as these: Unable to connect to your IMAP server. You may have exceeded the maximum c= onnections to this server. If so, use the IMAP server settings dialog to re= duce the number of cached connections. Sending of the message failed. The message could not be sent because the connection to Outgoing server (SM= TP) was lost in the middle of the transaction. Try again. I have used Thunderbird for years, and have really liked it. Sometimes one = of the top of the pages goes up way too high above the top of the screen, s= o there is no way...

Extension Uninstaller won't work and won't uninstall itself
I have a complicated profile that I don't want to have to recreate. I'm using SM 1.0.5, and I want to uninstall all of the extensions that I've installed that don't come from Mozilla. These are my current extensions: Chatzilla 0.9.67+ Extension Manager 2.0 Extension Uninstaller API 2.0 FlashGot NoScript Roaming I want to uninstall Flashgot, Noscript, the Extension Manager and the Extension Uninstaller API; however, the Extension Manager doesn't work; it won't uninstall either Flashgot nor Noscript, and I don&...

Firefox won't load, won't open web pages
I've had no trouble with FireFox until recently. Now here is what's happening: Firefox won't load, and won't open web pages. Faulting application firefox.exe, version 1.8.20060.50817, faulting module msctf.dll, version 5.1.2600.2180, fault address 0x000197db. For more information, see Help and Support Center at There is, of course, no help available from Microsoft. _Linda Amar_ spoke thusly on 02/06/2006 8:17 PM: > I've had no trouble with FireFox until recently. Now here is what's > happening: Fire...

portal.nlm won't load, so remote manager won't work...
Can't get any joy out of RM. This is on a 6.5 server with SP2 installed (though it says 5.7 SP1 at the end of boot...). Non-default stuff applied is MySQL and Veritas Backup Exec. Looking at the diocs it says portal.nlm must be loaded, but this isn't loading, saying it's UNRESOLVED I reordered the autoexec.ncf as per TID 10082078 Same thing happens on http-8008 or https-8009. Apache is working okay, I can get the basic server web welcome page. Any clues as to how I can get portal.nlm to load? Thanks, Pete. -- Peter Clinch Medical Physic...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\ to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified, it calls t/uni/, that, in, (when the path separators are '\'), the $file is '..\lib\unicore\To\' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

1. pages sometimes won't load 2. flash video players won't work
Name: Emmanuel Amodeo Email: emmanueldotamodeoatgmaildotcom Product: Firefox Summary: 1. pages sometimes won't load 2. flash video players won't work Comments: Hi, pages often won't finish loading. I have had this recurring problem with FF 3.5 ever since the official release of the program. A page will show that it is loading, and will not show anything onscreen until I chose to reload the page (select the adress in the adress bar and just press enter for reload). Once I tell the program to reload, it will show the page pretty much instantly. If I chose to let ...

Firefox crashes on start
I'm hoping someone can help me here. I've looked up and down google to try and find the answer to no avail. Suddenly, today, firefox stopped working. I was doing some maintenance on the computer and did the following: upgraded Spyware doctor and rescanned upgraded Registry Mechanie, did a registry fix and a computer optimization I have to assume the problem comes from there, since it was working fine before that. The first crash report I got referenced Since then, they've been different. I've uninstalled and reinstalled, nothing w...

Smart Tags won't open and some Intellisense won't fully work after installing LINQ CTP
I have installed the latest LINQ CTP.Some of the Intellisense stopped working. For example, writing:List<int> l=new with a space in the end, generally gives me a list of items, and List<int> is selected by default so I can press tab and get it written. After Installing LINQ it seems to be gone... Means no Intellisense is given. Only when hitting Ctrl+Space the list is shown but the default option is not selected.Another thing, when a smart tag is appears I'm unable to open it, hovering the small line expands the icon, but clicking the icon does nothing. Tried to hit Shift+Alt...

What did I do??? Help
I had a perfectly good web application running. I have a login page with a registration button and two text boxes Username, password along with a second button "submit". All worked except that hitting the enter key from the password text box sent the user to the registration page. I have been trying different options for getting the submit button click to occur when the user hits the enter key and the focus is on the password text box. I thought I undid all of my changes, but now my live application works as it did before but on my development copy on my local computer th...

User Control in UpdatePanel won't fire events
I have a User Control with a GridView on it that is dynamically loaded into an UpdatePanel using the LoadControl method. The GridView contains a ButtonField, but when clicked the Contol disappears and the gridView_RowCommand event never fires. If the control is not added dynamically but just put in the UpdatePanel the RowCommand event fires fine. Does anyone know a way around this? If you are dynamically adding this control inside the UpdatePanel then you will have to add it on each and every postback (inlcluding the async ones). It sounds to me like you are clicking the button in the Butt...

Won't run, won't quit...
Firefox won't open a page, it also won't completely quite. Task manager says that it's still running, and cannot close it. I left for about four weeks, and when I come back; this! I cannot end whatever part of firefox.exe is still running. IE works fine, but firefox will not find any page whatsoever. HELP? Yep. Even tried installing the latest version. Wouldn't work; it said the firefoxe.exe was still running, and I still could not close it. Matter of fact, it's "running" right now. I'm at a total loss here. There is no "uninstall"...

multiple buttons control event won't work on masterpage
this is my masterpage. I have 2 dropdownlist controls and 2 Button controls on my page. <%@ Master Language="VB" CodeFile="Masterp.master.vb" Inherits="ca.xasa" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""><html xmlns="" xml:lang="en" dir="rtl"> <head id="Head1" runat="server">  </head> <body> <div id="container"> <form...

EditableDataGrid won't work on Web User Control Page
I was working on Editable DataGrid aspx page. It had edit,update,cancel,paging functionality and textbox for searching database. It did its job perfect on aspx page, but using the same code on usercontrol page ,only thing that worked was search function. As soon as I pushed edit link datagrid became unvisible. Why is that? How can I get datagrid working on usercontrol page ? Any Ideas? The code: using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; us...

Web resources about - User Control Question: Button Onclick Event won't work (won't fire) -

Resources last updated: 1/10/2016 1:10:28 PM