【发布时间】:2011-07-31 17:57:21
【问题描述】:
我知道这种类型的问题已经被问过多次,但我花了好几个小时筛选不匹配或不起作用的答案,而我束手无策。
背景:我有一种情况,我想评估一条记录以确保它符合一组特定的标准。如果符合标准,请发出警报消息以供用户确认。除非条件匹配,否则我不想引发弹出窗口。
我想要完成的伪代码:
- 用户在多个字段中输入信息
- 用户点击“保存”(cmdUpdate)
- 在“保存”单击功能中,它会检查是否已存在相同的记录 在数据库中(例如,这是重复的)。
- 如果不是重复的,请继续使用保存功能
- 如果是重复的,则提示用户确认保存副本。
我无法在回发之前/之后显示弹出窗口。我尝试了一种设置会话值以维护状态的破解解决方法。该值在预渲染中测试为正,并且确实调用了 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, ByVal e As System.EventArgs)
SetSessionValue("HackWorkaround", False)
mpeSaveConfirmation.Enabled = False
mpeSaveConfirmation.Hide()
'do nothing and return to the screen.
End Sub
【问题讨论】:
标签: asp.net ajax vb.net .net-3.5 modalpopupextender