Hi, I am having a UpdatePanel inside which I have placed a button and an Accordion control. When the button is clicked it is fetching some data from database and the records are being displayed in Accordion as different panes. Among these results is an
ImageButton (with different image in every pane) for which I want to write a click event. When I click this image button it should display some other results inside a second Accordion control which is inside the first one. But this event is not working -
I mean that in debug mode I am able to see that the event is firing and the results are being fetched, but they are not being displayed in the second accordion. I am not clear where I am going wrong.
Can anyone tell me how to write events for dynamically generated buttons/imagebuttons inside an accordion?
Thanks in advance..
AccordionajaxAccordionPanedynamically created button in accordionbutton click inside accordionaccordion inside accordion
Since, you embedded the second accordion inside the first accordion, you need to take special care to get hold of the second accordion. In ASP.Net, the naming containers can contain other controls, but those controls are not directly accessible from the
codebehind. And Accordion controls are naming containers.
I assume you have two accordions, ParentAccordion and ChildAccordion, where child is nested within the parent.
With this setup, you need to use the following method:-
One more thing is that I need to get the selected item from the given accordion pane.I am able to go into the button click event if the ImageButton is same in all the panels. But for my requirement, I have different Image buttons depending on each record.Suppose
for a record with RecID =1, I have one image and for RecID=2 I have another image. These records are displayed in different panes in Accordion.
If I click the first ImageButton which is in first pane, I should get records from a child table whose RecID=1 (the field RecID is foreign key in the child table) and display them in child accordion. So my doubt is, how to capture the selected item, so that
I can recognise which ImageButton raised the event. Also, one more thing is that I wanted to place the ImageButton and the child accordion in an update panel. I am not sure whether that is the right thing to do or not. Please guide me with some code regarding
this. I am new to AJAX. Thanks a lot.
But for Gridview there are rowdatabound and rowcommand events. In which event should I write the code for accordion? And can you help me with a few lines of code? Also I want to display the results in a second accordion which is inside the first. I have
tried with findcontrol() but I am not able to understand how to do it. Any ideas?
using AjaxControlToolkit;
protected void LinksAcc_ItemDataBound(object sender, AccordionItemEventArgs e)
{
if (e.AccordionItem.ItemType == AccordionItemType.Content)
{
Button bu = ((Button)e.AccordionItem.Controls[1]);// you should check the location of your button
bu.CommandArgument = e.AccordionItem.DataItemIndex.ToString();
}
}
protected void LinksAcc_ItemCommand(object sender, CommandEventArgs e)
{
int index;
string lsField;
if (e.CommandName == "display")
{
index = Convert.ToInt32(e.CommandArgument); // The index of Button you clicking.
Response.Write(index.ToString());
}
}
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Marked as answer by Vince Xu - MSFT on Apr 29, 2009 02:28 AM
IamOnCloudNi...
Member
680 Points
178 Posts
Button click event inside Accordion
Apr 19, 2009 11:13 AM|LINK
Hi, I am having a UpdatePanel inside which I have placed a button and an Accordion control. When the button is clicked it is fetching some data from database and the records are being displayed in Accordion as different panes. Among these results is an ImageButton (with different image in every pane) for which I want to write a click event. When I click this image button it should display some other results inside a second Accordion control which is inside the first one. But this event is not working - I mean that in debug mode I am able to see that the event is firing and the results are being fetched, but they are not being displayed in the second accordion. I am not clear where I am going wrong.
Can anyone tell me how to write events for dynamically generated buttons/imagebuttons inside an accordion?
Thanks in advance..
Accordion ajax AccordionPane dynamically created button in accordion button click inside accordion accordion inside accordion
Sohan
Member
402 Points
66 Posts
Re: Button click event inside Accordion
Apr 19, 2009 04:52 PM|LINK
Since, you embedded the second accordion inside the first accordion, you need to take special care to get hold of the second accordion. In ASP.Net, the naming containers can contain other controls, but those controls are not directly accessible from the codebehind. And Accordion controls are naming containers.
I assume you have two accordions, ParentAccordion and ChildAccordion, where child is nested within the parent.
With this setup, you need to use the following method:-
(Accordion)ParentAccordion.FindControl("ChildAccordion")to get the instance of ChildAccordion. Then you can of course set the dynamic content.
I assume, you are already firing the event rightly as you said you could debug. This solution should work for you.
(Please, Mark as Answer if it Helped)
http://smsohan.blogspot.com
IamOnCloudNi...
Member
680 Points
178 Posts
Re: Button click event inside Accordion
Apr 19, 2009 05:12 PM|LINK
Thanks for the reply.. I'll try that.
One more thing is that I need to get the selected item from the given accordion pane.I am able to go into the button click event if the ImageButton is same in all the panels. But for my requirement, I have different Image buttons depending on each record.Suppose for a record with RecID =1, I have one image and for RecID=2 I have another image. These records are displayed in different panes in Accordion.
If I click the first ImageButton which is in first pane, I should get records from a child table whose RecID=1 (the field RecID is foreign key in the child table) and display them in child accordion. So my doubt is, how to capture the selected item, so that I can recognise which ImageButton raised the event. Also, one more thing is that I wanted to place the ImageButton and the child accordion in an update panel. I am not sure whether that is the right thing to do or not. Please guide me with some code regarding this. I am new to AJAX. Thanks a lot.
IamOnCloudNi...
Member
680 Points
178 Posts
Re: Button click event inside Accordion
Apr 21, 2009 09:41 AM|LINK
Anybody there to help???
Vince Xu - M...
All-Star
80367 Points
6801 Posts
Re: Button click event inside Accordion
Apr 22, 2009 07:57 AM|LINK
Hi,
You can build command bubble event for the button in Accordion. The row index you can assign to command argument of the button.
You can check this post http://forums.asp.net/t/1222400.aspx
It is about gridview, but they are the same thing on this question.
IamOnCloudNi...
Member
680 Points
178 Posts
Re: Button click event inside Accordion
Apr 24, 2009 05:36 PM|LINK
But for Gridview there are rowdatabound and rowcommand events. In which event should I write the code for accordion? And can you help me with a few lines of code? Also I want to display the results in a second accordion which is inside the first. I have tried with findcontrol() but I am not able to understand how to do it. Any ideas?
Vince Xu - M...
All-Star
80367 Points
6801 Posts
Re: Button click event inside Accordion
Apr 27, 2009 05:28 AM|LINK
Hi,
You can use OnItemCommand and OnItemDataBound instead.
Please check the below sample:
<ajaxToolkit:Accordion ID="LinksAcc" FadeTransitions="true" RequireOpenedPane="false" ContentCssClass="acc-content" CssClass="acc" HeaderSelectedCssClass="acc-selected-header" HeaderCssClass="acc-header" OnItemCommand="LinksAcc_ItemCommand" OnItemDataBound="LinksAcc_ItemDataBound" TransitionDuration="150" DataSourceID="SqlDataSource1" runat="server"> <HeaderTemplate> <h5><asp:Label runat="server" ID="label1" Text='<%#Eval("Name")%>'></asp:Label></h5> </HeaderTemplate> <ContentTemplate> <asp:Button runat="server" ID="Button1" Text="button" CommandName='display'/> </ContentTemplate> </ajaxToolkit:Accordion>