Reputation: 103
I have two update panels, the first update panel (up1) contains a repeater control which simply repeats a button control. When one of the buttons is clicked in up1, i simply want to update the second update panel (up2) using a paramater passed from the button in up1. Basically, each button has a conversation ID, so when clicked up2 will get all the messages from a conversation with that id. Because of other functionality, there needs to be two update panels.
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" EnablePartialRendering="true" runat="server" >
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="up1" OnLoad="up1_Load">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Button ID="Button1" runat="server"
CommandName="conversationID"
CommandArgument='<%# Eval("conversation_id") %>' />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="up2" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<p><%#Eval("message")%></p>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
I've tried passing command arguments in the code behind but it just doesn't work! Please can someone point me in the right direction?
Many thanks
Upvotes: 2
Views: 3391
Reputation: 6184
Look up AsyncPostBackTriggers as a way to get a clientside control to trigger an UpdatePanel to do a partial page refresh. I've tied two update panels together that way many times...
<UpdatePanel>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=”up1” />
</Triggers>
<ContentTemplate>
....
</ContentTemplate>
</UpdatePanel>
I don't remember offhand whether you can link the actual UpdatePanels together or if you'll have to add a trigger rule for every repeater button in your up1 UpdatePanel
Upvotes: 1
Reputation: 3294
Since UpdatePanel is for dynamic content (e.g. AJAX), the best place to update the second panel is in the client (e.g. in JavaScript) instead of in the code-behind at the server.
Also, your code will be cleaner if there are no code blocks in your .aspx file. For example, declare a Button
variable for button1
in your code behind and set the CommandArgument attribute in the page's PageLoad
or PageInit
instead of using inline code and Eval
Upvotes: 0