C# 显示模式弹出登录后等待用户响应
在我的代码隐藏文件中,我调用了一个html模式弹出窗口,提示用户输入用户名和密码。 在继续之前,我希望将结果返回到调用函数的代码隐藏中。 我该怎么做?现在显示了模态形式,c代码继续处理,这是有意义的,但不是我想要的。 注意:模式签核html模式表单有一个按钮(btnSignoff),用于调用其他一些代码隐藏函数 谢谢 达莫C# 显示模式弹出登录后等待用户响应,c#,asp.net,ajaxcontroltoolkit,C#,Asp.net,Ajaxcontroltoolkit,在我的代码隐藏文件中,我调用了一个html模式弹出窗口,提示用户输入用户名和密码。 在继续之前,我希望将结果返回到调用函数的代码隐藏中。 我该怎么做?现在显示了模态形式,c代码继续处理,这是有意义的,但不是我想要的。 注意:模式签核html模式表单有一个按钮(btnSignoff),用于调用其他一些代码隐藏函数 谢谢 达莫 <asp:Button ID="btnSignoff" runat="server" Text="Signoff" /> // handles Cance
<asp:Button ID="btnSignoff" runat="server" Text="Signoff" />
// handles Cancel action...
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
...
<!-- End Signoff Modal Form -->
代码隐藏:
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
}
<!-- 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 -->
<asp:Button ID="btnSignoff" runat="server" Text="Signoff" />
// handles Cancel action...
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
...
<!-- End Signoff Modal Form -->
SignoffModal.Show();
//等待响应(这是我希望能够做到的)
如果(结果)
看起来,ModalPopupXtender的设计不是这样的。虽然它是模态的(防止用户与页面的其余部分交互),它没有阻塞,表示调用表单后代码继续运行。这是因为弹出窗口在客户端上运行,而隐藏的代码运行服务器。这称为a,因为在执行操作时客户端代码会回调服务器
<asp:Button ID="btnSignoff" runat="server" Text="Signoff" />
// handles Cancel action...
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
...
<!-- End Signoff Modal Form -->
要实现这一点,您必须通过在ModalPopupXtender
上添加CancelControlID
属性,将SignoffModal.Show();
之后的逻辑拆分为“确定”部分和“取消”部分,指向处理取消操作的按钮,然后添加按钮:
<!-- 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 -->
在btnCancel
代码隐藏事件处理程序中:
<asp:Button ID="btnSignoff" runat="server" Text="Signoff" />
// handles Cancel action...
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
...
<!-- End Signoff Modal Form -->
{
// Do some work...
{
//throw some error...
您好,所以基本上您是说:这是不可能的,我必须继续使用btnsignoff的代码隐藏进行处理。我可以这样做,但我希望signoff模式+其代码隐藏在我希望用户名和密码注销的其他情况下是可重用的。您说的对吗?您仍然可以使代码可重用,只是您必须按照ModalPopupXtender所期望的方式连接代码。这意味着一块代码用于“确定”,另一块代码用于“取消”。只需为每个代码块创建函数,然后在其他应用程序中从按钮偶数处理程序调用函数。最后,我将会话变量设置为第一个函数的值。然后我检查t当调用第二个函数时,该会话变量被设置为并在switch语句列表中运行,以执行所需的函数。