asp.net – ModalPopupExtender没有在updatepanel中的按钮回发上
我知道这个问题有多次被问过,但是我花了几个小时来筛选那些不匹配或不起作用的答案,而且我很有智慧.
背景:我有一种情况,我想评估一条记录,以确保它符合一组特定的标准.如果符合条件,请发出警报消息以供用户确认.除非标准匹配,否则我不想提升弹出窗口. 我想要完成的伪代码: >用户在多个字段中输入信息 我无法在回发之前/之后显示弹出窗口.我尝试过设置会话值以维持状态的黑客解决方法.该值在预渲染中测试为正,并且调用modalpopupextender.show但它从未成功触发到屏幕.我不反对切换到javascript解决方案,如果有人有更好的方法,但我必须检查后面的asp.net代码中的重复项. 标记: <asp:UpdatePanel ID="upMainContent" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False" > <ContentTemplate> <asp:Label ID="lblDummy" runat="server" EnableViewState="false" Style="display: none;" /> <asp:Panel ID="pnlConfirmation" runat="server" Width="400px" Style="display: none;" CssClass="ModalPopupFront"> <div ID="Div1" runat="server" class="PopupHeader" style="width:400px;"> Duplicate Record</div> <br /> <asp:Label ID="lblConfirmationMessage" runat="server" Text="This record has already exists.<br/> Are you sure you want to save a duplicate entry?"></asp:Label><br /> <br /> <div style="text-align:right;"> <asp:Button ID="btnSaveAnyway" runat="server" Text="Save" OnClick="btnSaveAnyway_Click" /> <asp:Button ID="btnCancelSave" runat="server" Text="Cancel" OnClick="btnCancelSave_Click" /> </div> </asp:Panel> <ajax:ModalPopupExtender ID="mpeSaveConfirmation" runat="server" Enabled="False" TargetControlID="lblDummy" PopupControlID="pnlConfirmation" BackgroundCssClass="modalBackground" DropShadow="true" CancelControlID="btnCancelSave" RepositionMode="RepositionOnWindowResizeAndScroll" PopupDragHandleControlID="pnlConfirmation" Drag="true"> </ajax:ModalPopupExtender> <!-- all the input fields/misc content --> <asp:Button id="cmdUpdate" runat="server" CausesValidation="true" OnClick="cmdUpdate_Click" Text="Save" ValidationGroup="vg1" ToolTip="Save the current record" TabIndex="102" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlStateId" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="ddlCountyId" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> 代码背后: Protected Sub Page_PreRender(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.PreRender '... If GetSessionValue("HackWorkaround") Then mpeSaveConfirmation.Enabled = True mpeSaveConfirmation.Show() End If End Sub Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load '... If not Page.IsPostBack Then SetSessionValue("HackWorkaround",False) End if '... End Sub Protected Sub cmdUpdate_Click(ByVal sender As Object,ByVal e As System.EventArgs) If tbOpTill.NewRecordIdenticalToLast() And tbOpRecord.NewRecordIdenticalToLast() Then SetSessionValue("HackWorkaround",True) Else SetSessionValue("HackWorkaround",False) SetSessionValue("LastOpRecordIDSaved",tbOpRecord.OpRecordId) Dim isEdit As Boolean = ResetOpRecord("Till",tbOpTill) SmartRedirect("Optill/oprecord_edit.aspx") End If End Sub Protected Sub btnSaveAnyway_Click(ByVal sender As Object,ByVal e As System.EventArgs) SetSessionValue("HackWorkaround",False) mpeSaveConfirmation.Enabled = False mpeSaveConfirmation.Hide() 'Duplicate record exists,but the customer wants to save anyway. DoSave() Dim isEdit As Boolean = ResetOpRecord("Till",tbOpTill) SmartRedirect("Optill/oprecord_edit.aspx") End Sub Protected Sub btnCancelSave_Click(ByVal sender As Object,False) mpeSaveConfirmation.Enabled = False mpeSaveConfirmation.Hide() 'do nothing and return to the screen. End Sub 解决方法
你的问题在这里:
<ajax:ModalPopupExtender ID="mpeSaveConfirmation" runat="server" Enabled="False" Protected Sub btnSaveAnyway_Click(ByVal sender As Object,False) **mpeSaveConfirmation.Enabled = False** mpeSaveConfirmation.Hide() 在后面的代码中使它成为现实.和sync同步隐藏显示.此外,我可以在您的代码中看到您正在使用Style =“display:none”的某些地方.所以如果你想显示你需要使用HtmlStyleWriter.Display,“阻止”.如果在这种情况下使用Visible true false,它将无效.我的意思是说,无论你在哪里使用可见的真假,在代码隐藏中你必须使用类似的.如果您正在使用样式,那么在代码隐藏中您必须使用相同的样式. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-core – 你如何解决AspNet Core缺少的依赖关系?
- asp.net-mvc – LINQ到EF有什么问题?
- asp.net-mvc – MVVM ViewModel vs. MVC ViewModel
- Kendo UI ASP.NET MVC使用教学视频集锦(高清在线观看)
- asp.net-core – asp.net核心依赖注入问题 – AddScoped没有
- asp.net – 会话存储在客户端或服务器端
- 如何在ASP.NET 5中使用SignalR
- asp.net – 如何保护我的通用处理程序调用?
- AntiForgery令牌使用ASP.NET5 Web API而不使用NET46上的Sys
- asp.net – 如果Ninject尚未绑定,如何在Ninject中绑定?