我有两个更新面板,第一个更新面板(up1)包含一个转发器控件,它只是重复一个按钮控件。当在up1中单击其中一个按钮时,我只想使用从up1中的按钮传递的参数更新第二个更新面板(up2)。 基本上,每个按钮都有一个会话ID,因此当点击up2时,将获得具有该ID的会话中的所有消息。由于其他功能,需要有两个更新面板。
<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>
我已经尝试在后面的代码中传递命令参数,但它只是不起作用!请有人指出我正确的方向吗?
非常感谢
答案 0 :(得分:1)
查找AsyncPostBackTriggers,以获取客户端控件以触发UpdatePanel进行部分页面刷新。我已经多次将两个更新面板绑在一起......
<UpdatePanel>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=”up1” />
</Triggers>
<ContentTemplate>
....
</ContentTemplate>
</UpdatePanel>
我不记得你是否可以将实际的UpdatePanel链接在一起,或者你是否必须为up1 UpdatePanel中的每个转发器按钮添加一个触发器规则
答案 1 :(得分:0)
由于UpdatePanel用于动态内容(例如AJAX),更新第二个面板的最佳位置是在客户端(例如在JavaScript中),而不是在服务器的代码隐藏中。
此外,如果.aspx文件中没有代码块,您的代码将更加清晰。例如,在后面的代码中为Button
声明button1
变量,并在页面的PageLoad
或PageInit
中设置CommandArgument属性,而不是使用内联代码和Eval
}