ASP .NET 从另一个更新面板中的转发器按钮控制更新面板

发布于 2024-07-27 20:52:06 字数 1267 浏览 0 评论 0原文

我有两个更新面板,第一个更新面板(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捶死心动 2024-08-03 20:52:06

查找 AsyncPostBackTriggers 作为获取客户端控件以触发 UpdatePanel 进行部分页面刷新的方法。 我已经多次以这种方式将两个更新面板捆绑在一起...

<UpdatePanel>
   <Triggers>
     <asp:AsyncPostBackTrigger ControlID=”up1” />
   </Triggers>
   <ContentTemplate>
     ....
   </ContentTemplate>
</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...

<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

寻找一个思念的角度 2024-08-03 20:52:06

由于UpdatePanel 用于动态内容(例如AJAX),因此更新第二个面板的最佳位置是在客户端(例如在JavaScript 中)而不是在服务器的代码隐藏中。

另外,如果 .aspx 文件中没有代码块,您的代码将会更加干净。 例如,在后面的代码中为 button1 声明一个 Button 变量,并在页面的 PageLoadPageInit 而不是使用内联代码和 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 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文