Hello,
I am trying to create buttons dynamically (server side) and add these as controls to a panel which statically defined inside a radupdatepanel. There is no problem with the creation but I also have to attach click events to these dynamically created buttons and let them fire when they are clicked in an AJAX manner.
Here are some specific excerpts from my code...
C#
and the associated click event...
and the excerpt from the ascx section...
When the ascx is rendered, I type some candidate tags to the textbox (rtbTag) and click on Add button (btnNewTag), this works fine. The tag is added to the panel using AJAX principles (partial refreshing, loading panel is displayed etc.). But what I could not accomplish is that the neighbor button to the added tags does not work at all...
Any recommendations?
I am trying to create buttons dynamically (server side) and add these as controls to a panel which statically defined inside a radupdatepanel. There is no problem with the creation but I also have to attach click events to these dynamically created buttons and let them fire when they are clicked in an AJAX manner.
Here are some specific excerpts from my code...
C#
foreach (DataRow aRow in dt.Rows) |
{ |
HyperLink oTagLink = new HyperLink(); |
oTagLink.CssClass = "Tag"; |
oTagLink.Text = aRow[JobTag.Columns.Name].ToString(); |
oTagLink.NavigateUrl = ""; |
Button oRemoveTagBtn = new Button(); |
oRemoveTagBtn.CssClass = "RemoveTag"; |
oRemoveTagBtn.Text = "[x]"; |
oRemoveTagBtn.Attributes.Add("TagId", aRow[JobTag.Columns.Id].ToString()); |
oRemoveTagBtn.Click += new EventHandler(btnRemoveTag_Click); |
pnlTags.Controls.Add(oTagLink); |
pnlTags.Controls.Add(oRemoveTagBtn); |
} |
and the associated click event...
protected void btnRemoveTag_Click(object sender, EventArgs e) |
{ |
Button clicked = (Button)sender; |
oJobManager.RemoveAssociatedTag(Convert.ToInt32(clicked.Attributes["TagId"])); |
pnlTags_NeedDataSource(); |
} |
and the excerpt from the ascx section...
<telerik:RadAjaxLoadingPanel Transparency="20" BackColor="White" ID="LoadingPanel1" |
runat="server" Style="width: 320px; padding-top: 125px;" Height="110px" Width="110px" |
meta:resourcekey="LoadingPanel1Resource1"> |
<img alt="Loading..." src="../../Images/progress.gif" style="border: 0;" /> |
</telerik:RadAjaxLoadingPanel> |
<telerik:RadAjaxPanel runat="server" ID="rapTags" LoadingPanelID="LoadingPanel1" |
HorizontalAlign="NotSet"> |
<asp:Label ID="lblTagsSection" runat="server" Text="Tags:"></asp:Label> |
<br /> |
<asp:Label ID="lblNewTag" runat="server" Text="New Tag:"></asp:Label> |
<telerik:RadTextBox ID="rtbTag" Width="150px" runat="server"> |
</telerik:RadTextBox> |
<asp:Button ID="btnNewTag" runat="server" Text="Add" OnClick="btnNewTag_Click" /> |
<br /> |
<br /> |
<asp:Label ID="lblTags" runat="server" Text="Associated Tags:"></asp:Label> |
<br /> |
<br /> |
<div style="width: 700px; height: 100px; overflow: auto;"> |
<asp:Panel ID="pnlTags" runat="server"> |
</asp:Panel> |
</div> |
</telerik:RadAjaxPanel> |
When the ascx is rendered, I type some candidate tags to the textbox (rtbTag) and click on Add button (btnNewTag), this works fine. The tag is added to the panel using AJAX principles (partial refreshing, loading panel is displayed etc.). But what I could not accomplish is that the neighbor button to the added tags does not work at all...
Any recommendations?