ASP .NET 从另一个更新面板中的转发器按钮控制更新面板
我有两个更新面板,第一个更新面板(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>
我尝试过在后面的代码中传递命令参数,但它不起作用! 请有人指出我正确的方向吗?
非常感谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查找 AsyncPostBackTriggers 作为获取客户端控件以触发 UpdatePanel 进行部分页面刷新的方法。 我已经多次以这种方式将两个更新面板捆绑在一起...
我不记得是否可以将实际的 UpdatePanel 链接在一起,或者是否必须为 up1 UpdatePanel 中的每个转发器按钮添加触发规则
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...
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
由于UpdatePanel 用于动态内容(例如AJAX),因此更新第二个面板的最佳位置是在客户端(例如在JavaScript 中)而不是在服务器的代码隐藏中。
另外,如果 .aspx 文件中没有代码块,您的代码将会更加干净。 例如,在后面的代码中为
button1
声明一个Button
变量,并在页面的PageLoad
或PageInit 而不是使用内联代码和
Eval
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 forbutton1
in your code behind and set the CommandArgument attribute in the page'sPageLoad
orPageInit
instead of using inline code andEval