2011-04-07 95 views
4

我知道这个问题的味道已被多次询问,但我已花费数小时筛选不匹配或不工作的答案,并且我正处于结束状态。ModalPopupExtender在updatepanel内的按钮回发中不显示

背景:我有一种情况,我想评估一条记录以确保它符合特定的一组标准。如果它符合标准,请提出警告消息以供用户确认。除非标准匹配,否则我不想提高弹出窗口。

伪代码是什么我要完成:

  • 用户在多个领域的信息
  • 用户点击“保存”(cmdUpdate)
  • 它检查“保存”点击函数中查看数据库中是否存在相同的记录 (例如,这是重复的)。
  • 如果不是重复继续保存功能
  • 如果它是一个重复的提示用户确认保存dup。

我无法获取弹出窗口以在回发之前/之后显示。我已经尝试了一个设置会话值以维护状态的黑客解决方法。该值在prerender中测试为正值,并确实调用了modalpoputentender.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;">&nbsp;&nbsp;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 

回答

2

你的问题就在这里:

<ajax:ModalPopupExtender ID="mpeSaveConfirmation" runat="server" Enabled="False" 

Protected Sub btnSaveAnyway_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    SetSessionValue("HackWorkaround", False) 
    **mpeSaveConfirmation.Enabled = False** 
    mpeSaveConfirmation.Hide() 

让它在代码中真正的后面。并相应地隐藏显示。另外我可以在你的代码中看到你正在使用Style =“display:none”的地方。所以如果你想显示你需要使用HtmlStyleWriter.Display,“块”。如果在这种情况下使用Visible true false,它将不起作用。我的意思是说,在任何时候你使用可见的真实假,在代码隐藏你必须使用类似的。如果您使用的是风格,那么在代码隐藏中,您必须使用相同的风格。

+0

删除设置.Enabled true/false的代码解决了问题。在这种情况下,我不明白该财产的目的,但它的工作让我愿意放手。谢谢。 – jasonk 2011-04-13 13:27:50