【问题标题】:asp.net Update Panel capturing Button clicksasp.net 更新面板捕获按钮点击
【发布时间】:2011-10-08 21:40:34
【问题描述】:

我有一个页面,上面有一个 ASP.NET UpdatePanel。 UpdatePanel 包含一个中继器,中继器内是一个命令按钮。 (请看下面的代码示例)

当我第一次点击按钮时,什么也没有发生。但是第二次点击同一个按钮时,我得到了我期望触发的事件。我不知道为什么会这样,尽管我确信有一个简单的解释。任何建议都会有所帮助。

<!-- Drivers Table -->
                    <asp:UpdatePanel runat="server" ID="DriverUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="true">
                        <ContentTemplate>    
                            <asp:HiddenField runat="server" ID="DriverErrors" />
                            <asp:Repeater ID="DriverRepeater" runat="server" OnItemDataBound="DriverRepeater_ItemDataBound" OnItemCommand="DriverRepeater_ItemCommand">
                                <HeaderTemplate>
                                    <table cellspacing="0" class="section-table">
                                        <tr>
                                            <td class="bg_mid" colspan="7"><img src="/images/sections/drivers.png" alt="Drivers" /></td>
                                        </tr>
                                        <tr>
                                            <td class="text_1 left-cell">#</td>
                                            <td class="text_1">Name</td>
                                            <td class="text_1">Date Of Birth</td>
                                            <td class="text_1">Gender</td>
                                            <td class="text_1">License #</td>
                                            <td class="text_1">Relationship</td>
                                            <td class="text_1" align="right">&nbsp;</td>
                                        </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                        <tr id="DriverRow" runat="server">
                                            <td class="text_2 required left-cell"><asp:Label ID="DriverNumber" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DriverNumber")%>'></asp:Label></td>
                                            <td class="text_2 required"><asp:Label ID="DriverName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "FirstName")%>'></asp:Label></td>
                                            <td class="text_2 required"><asp:Label ID="BirthDate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "BirthDate")%>'></asp:Label></td>
                                            <td class="text_2 required"><asp:Label ID="Gender" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Gender").ToString() == "F" ? "Female" : "Male" %>'></asp:Label></td>
                                            <td class="text_2 required"><asp:Label ID="DriversLicenseNumber" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "LicenseInformation.DriversLicenseNumber")%>'></asp:Label></td>
                                            <td class="text_2 required"><asp:Label ID="RelationshipToApplicant" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "RelationshipToApplicant")%>'></asp:Label></td>
                                            <td class="text_2 right-cell" align="right"><asp:ImageButton runat="server" ID="DriverEditButton" 
                                                ImageUrl="/images/edit.jpg" AlternateText="Edit" CommandName="Edit" CausesValidation="false" /></td>
                                        </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </table>
                                </FooterTemplate>
                            </asp:Repeater>
                        </ContentTemplate>
                    </asp:UpdatePanel>

【问题讨论】:

  • 我刚刚注意到的另一件事。渲染后的第二次点击。因此,如果我在任何时候调用面板上的更新,则需要再次单击两次才能触发事件。
  • 如果您将 updatemode 更改为 Always 是否总是会引发您所期望的事件?页面上是否还有其他 UpdatePanel?
  • 我尝试将其更改为 Always,但这实际上会在 hte 后端调用 Update() 面板时引发错误。页面上有多个更新面板。

标签: asp.net ajax updatepanel


【解决方案1】:

制作UpdatePanel Mode="Conditional"enableviewstate="true" 你不需要定义触发器,没有它你的工作就完成了。

【讨论】:

  • 谢谢,我会试试看是否有帮助
  • 不,在这种情况下没有帮助
猜你喜欢
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多