views:

1250

answers:

2

Hi

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

A: 

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

Jeff Leonard
I've tried adding an onclick event to the buttons which passes the conversation id number to a function within javascript code. This then calls a method within my codebehind which updates the updatepanel. for example: function CallMyMethod(cid) { PageMethods.MyMethod(cid, MyMethod_Result); }The problem is that the webmethod subroutine it calls has to 'shared' to communicate, for example: <WebMethod()> _ Public Shared Sub MyMethod(ByVal CId As Integer) ..get sql data, bind to repeater in updatepanel2 End Sub
the problem with this is that when i try to bind the data i get the following error:cannot refer to an instance member of a class from within a shared method
+1  A: 

Hi,

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

Neil Fenwick