0

在我的文件后面的代码中,我调用了一个 html 模式弹出窗口,它提示用户输入他们的用户名和密码。在继续之前,我想从这个返回到我调用函数后面的代码。我该怎么做呢?现在显示了模态表单,并且 c# 代码继续处理这是有道理的,但它不是我想要的。注意: modal signoff html modal form 有一个按钮(btnSignoff),它调用一些其他代码隐藏函数感谢Damo

后面的代码:

SignoffModal.Show();
//Wait for response (this is what i would like to be able to do)
if (result <0)
{
//throw some error
}

else
{
// Do some more work
}

HTML 代码:

 <!-- Signoff Modal Form -->
                <asp:HiddenField ID="SignoffForModal" runat="server" />
                <ajaxToolkit:ModalPopupExtender runat="server" ID="SignoffModal" BehaviorID="modalPopupExtenderSignoff"
                    TargetControlID="SignoffForModal" PopupControlID="popUpPaneSignoff" OkControlID="btnSignoff"
                    BackgroundCssClass="modalBackground">
                </ajaxToolkit:ModalPopupExtender>
                <asp:Panel ID="popUpPaneSignoff" runat="server" CssClass="confirm-dialog">
                    <asp:Label ID="lblUsername" runat="server" Text="Username"></asp:Label>
                    <br />
                    <asp:TextBox ID="txtUserName" runat="server" ToolTip="Username" Width="200px"></asp:TextBox>
                    <br />
                    <asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Label>
                    <br />
                    <asp:TextBox ID="txtPassword" runat="server" ToolTip="Password" TextMode="Password"
                        Width="200px"></asp:TextBox>
                    <br />
                    <br />
                    <div class="base">
                        <asp:Button ID="btnSignoff" runat="server" Text="Signoff" />
                        <asp:LinkButton ID="LinkButton3" runat="server" CssClass="close" OnClientClick="$find('modalPopupExtenderSignoff').hide(); return false;" /></div>
                </asp:Panel>
                <!-- End Signoff Modal Form -->
4

1 回答 1

1

好像ModalPopupExtender不是这样设计的。虽然它是模态的(防止用户与页面的其余部分交互),但它不是阻塞的,意味着代码在调用表单后继续运行。那是因为弹出窗口在客户端上运行,而代码隐藏在服务器上运行。这称为回调,因为客户端代码在执行操作时回调到服务器。

为了使这项工作,您必须通过添加一个指向处理取消操作的按钮的属性来将您之后的逻辑拆分为SignoffModal.Show();“确定”部分和“取消”部分,然后添加按钮:CancelControlIDModalPopupExtender

  <!-- Signoff Modal Form -->
<asp:HiddenField ID="SignoffForModal" runat="server" />
<ajaxToolkit:ModalPopupExtender runat="server" ID="SignoffModal" 
    BehaviorID="modalPopupExtenderSignoff"
    TargetControlID="SignoffForModal" 
    PopupControlID="popUpPaneSignoff"     
    OkControlID="btnSignoff" 
 // points to cancel button action
    CancelControlID="btnCancel" 
 BackgroundCssClass="modalBackground">

...

<asp:Button ID="btnSignoff" runat="server" Text="Signoff" />
    // handles Cancel action...
    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
    ...
<!-- End Signoff Modal Form -->

btnSignoff代码隐藏事件处理程序中:

{
// Do some work...

btnCancel代码隐藏事件处理程序中:

{
//throw some error...
于 2012-08-25T23:00:23.707 回答