This is a migrated thread and some comments may be shown as answers.

Dynamically Created Buttons inside RadUpdatePanel and their onClick Events

3 Answers 145 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
NMA
Top achievements
Rank 1
NMA asked on 13 Jan 2009, 09:48 AM
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#
            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?








3 Answers, 1 is accepted

Sort by
0
NMA
Top achievements
Rank 1
answered on 14 Jan 2009, 09:36 AM
Could anyone help me to sort this out please?
0
Accepted
Iana Tsolova
Telerik team
answered on 14 Jan 2009, 11:36 AM
Hi,

I followed your scenario and prepared a sample project for you. Please try it on your end and let me know how it works and if I missed something from your scenario.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
NMA
Top achievements
Rank 1
answered on 15 Jan 2009, 12:17 PM
Thanks Iana,

I have followed your sample files and was able to overcome this problem... :)
Tags
Ajax
Asked by
NMA
Top achievements
Rank 1
Answers by
NMA
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or