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:

-----------------------------------------------------------------------------------------------------------------

<table cellpadding="0" cellspacing="0" border="0" width="100%">

<tr>

<td>

<asp:Image ID="Image2" runat="server" ImageUrl="~/Images/templateimages/menuHeader.jpg" AlternateText=""/>

</td>

</tr>

<tr>

<td align="left" style="padding-left:5px;">

<asp:LinkButton ID="lnkMyArticles" CssClass="menuCategories" Text="My Articles" runat="server" OnClick="lnkMyArticles_Click"/>

</td>

</tr>

<tr>

<td align="left" style="padding-left:5px;">

<asp:LinkButton ID="lnkMyProfile" CssClass="menuCategories" Text="My Profile" runat="server" OnClick="lnkMyProfile_Click"/>

</td>

</tr>

<tr>

<td align="left" style="padding-left:5px;">

<asp:LinkButton ID="lnkMyThemes" CssClass="menuCategories" Text="My Themes" runat="server" OnClick="lnkMyThemes_Click"/>

</td>

</tr>

</table>

---------------------------------------------------------------------------------------------------------------- 

My Code Behind:

protected void Page_Load(object sender, EventArgs e)

{

}

protected void lnkMyArticles_Click(object sender, EventArgs e)

{

//Load the "articles" menu

LoadUserControl("menuArticles");

}

protected void lnkMyProfile_Click(object sender, EventArgs e)

{

//Load the "profile" menu

LoadUserControl("menuProfile");

}

protected void lnkMyThemes_Click(object sender, EventArgs e)

{

//Load the "themes" menu

LoadUserControl("menuThemes");

}

/// <summary>

/// Returns the viewstate of the current user control loaded into memory

/// </summary>

public string TrackedUserControl

{

get { return ViewState["TrackedUserControl"] as string; }set { ViewState["TrackedUserControl"] = value; }

}

/// <summary>

/// The LoadControl method on the Page class takes the URL of an ASP.NET user control and loads

/// it into memory as an instance of a class that derives from UserControl

/// </summary>

/// <param name="menuState">name of the user control to load</param>

private void LoadUserControl(string userControlName)

{

MasterPage mstr; //used to reference webcontrols on masterpage

PlaceHolder placeHolder; //updates place holder webcontrol on masterpage

string ucUrl = "~/User controls/Menu/" + userControlName + ".ascx";

UserControl uc = null;

try

{

uc =
this.LoadControl(ucUrl) as UserControl;

}

catch (Exception ex)

{

}

if (uc != null)

{

mstr = Page.Master;

placeHolder = (
PlaceHolder)mstr.FindControl("phMenuContent");if (placeHolder != null)

{

placeHolder.Controls.Add(uc);

TrackedUserControl = ucUrl;

}

}

}

 --------------------------------------------------------------------------------------

Any idea how to get the onclick event to fire?

Thanks.

-Goalie35

0
Goalie35
2/27/2009 3:12:42 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

1 Replies
765 Views

Similar Articles

[PageSpeed] 31

 hi,

Your code is working properly i.e. all the click events are firing properly. If your problem is other can you give me clear explanation.

 

Mark as ANSWER if you got the solution from this post. 


Regards,
Ravi Kishore.Ch

Mark as "ANSWER" if you got the solution from this post.
0
chravikishore
2/27/2009 7:28:23 AM
Reply:

Similar Artilces:

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. Partial 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! ...

Label control's text doesn't appear to be set (in the page which has a user control )when trying to update the text property in the FormView's ItemUpdated event
Hi There,I have a user control which hosts a formview control, gridview control and a label control. The grid view is usedto show rows in the DB and when clicked to edit each row, a form view opens up in edit mode with that particular row info. So I have nothing in the item template.My first question is..is it mandatory to have smth in the itemtemplate of the form view.I have controls in edititemtemplate and insertitemtemplate.When a particular row is edited, I would like to show a status msg showing that the row has been updated.For this, I use the ItemUpdated event of the formview and try ...

Dynamically loading user control to a gridview
Hello,I know there are many posts about loading user control dynamically and events which not fire. I tried  everything suggested but nothing helped. The difference in my example is that I am loading the user control into a specific line in a grid view after the user clicked on a button.So, the containing object in this case is DataControlFieldCell but it is a difference one on every click of the user.I tried to to set the ID of the user control on the page load of the control (this.ID = "MyControl1";) and I am loading the control on post back in the page_load of the parent pa...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

custom control events add dynamically won't fire
I have a custom user control which I created.  It has a public event on it Public Event AddressDeleted(). This control is in a repeater on another control.  During the ItemBound event of the repeater I attached to that event. Private Sub rptAddresses_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptAddresses.ItemDataBound If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then Dim ctlAddress As wucUserAddress = e.Item.FindControl("wucUserAddress")...

Dynamically Populated Control in an UpdatePanel Won't Fire OnClick Event.
Hi all. I seem to be having some trouble with creating dynamic controls in a panel within an UpdatePanel.  I would like to be able to create controls dynamically, add them to a panel, and have their events fire as if they'd been there the entire time.  Everything seems to go well in populating the panel with the new control, but when I click on the new control the OnClick function doesn't fire.  I've prepared a simple, functional example case which appears at the end of this post. Any thoughts?  <%@ Page Language="C#" AutoEventWireup=...

How would I make a custom control's button's onclick event public?
I'd like to do something programatically in the parent class once a custom control's button is clicked.Anyone has a link to a tutorial?  http://msdn2.microsoft.com/en-us/library/aa645739(VS.71).aspxThanks, EdMicrosoft MVP - ASP/ASP.NET thanks but I'm looking for a tutorial for asp.net since I'm not too sure how the intricacies of asp.net change or simplify that example  http://www.odetocode.com/Articles/94.aspxThanks, EdMicrosoft MVP - ASP/ASP.NET thanks a lotI feel mildly dumb now  ...

Why can't I add controls dynamically to my customer server control?
This is a simple example of a custom control where I dynamically add a new control to the hierarchy. The problem is when I click the 'C' button, it adds the B button and then the next click of the 'C' button will hit the B_Click event handler. My only theory is that since it was added to the middle of the control heirarchy, then event handling got confused. Has anyone seen this problem or am I doing something wrong? using System; using System.Configuration; using System.Collections; using System.Text.RegularExpressions; using System.Xml; using System.Data; using S...

Table Cell click event
Hi, I used to have a custom server control inhirted from TableCell control to implement click event in VS.NET 2003.  When I use the custom control in VS.NET 2003 Web application (dynamically adding to table object), everything works fine.  Below is the code from 2003 project, and everything works good in this way.                 Dim c As New MyCustomTableCell                  c.Width = 200     &nb...

Click event won't fire in custom control..
Hi all.   We have a requirement to return the (pixel) coordinates specifying where a user has clicked on an image (its an asp.net front-end hitting a cold-fusion web-service interacting with a GIS mapping system).   The new ImageMap control in asp.net 2.0 offers a 'Click' event but due to the way HTML imagemaps work it can't parse the co-ordinates that are returned in the querystring (they are malformed).   So I found a control that a fellow has made which extends the ImageMap control making available the coordinates as arguments of the click-event: http://www.code...

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...

Why can't fire the child datalist's event which is a template control of datalist ?
I can't the fire the child datalist edit/update/cancel event which in the parent datalist template: this is aspx file: <asp:datalist id="categoryDataList" runat="server"> <ItemTemplate> <table > <tr> <td><%# DataBinder.Eval(Container.DataItem, "Name" ) %></td> <td> <asp:ImageButton ID = "EditCategory" Runat ="server" ImageUrl ="Images/Edit.gif" BorderWidth ="0" CommandName ="Edit"></asp:ImageButton>&nbsp;&nbsp; ...

User Controls won't see each other user controls in same namespace
I've browse alot for this error but I can't find any answer to my problem. Please help !!!!I am creating a PageMenu user control which contains several PageMenuItems. Both compile without any problem and I would like PageMenuItems to call PageMenu's click event when a click event is received. I am trying to cast PageMenuItems's Parent property to access PageMenu. In the namespace I created, I PageMenuItems won't see PageMenu. The only way I could make PageMenuItems see PageMenu was by registering the control in the aspx file.I also realized that both PageMenu and PageMenuItems would not see ...

controls won't update or events fire on server side in AJAX application.
I have an ajax app with VB.NET on the server side and javascript on the client side, which uses callbacks. On the page I have several check boxes, radio buttons, text boxes and slider extenders. The client calls code on the server, but when the server code reads the controls they see the initial values, not the current values.  I tried using "change" events for the controls, but they won't fire on the server side. I also tried putting them all in an update panel triggered on the events of those controls, but it still doesn't work.  Everything works OK on the cli...

Web resources about - Dynamic user control's onclick event won't fire - asp.net.custom-server-controls

Resources last updated: 12/21/2015 12:06:03 PM