我正在使用 asp.net 创建一个网站。如果用户单击登录链接,我将调用模态对话框。
这是我的 showModalDialog 脚本。
<li><a onclick="popup()"href="#">LOGIN</a></li>
<script type="text/javascript">
function popup() {
var style = 'dialogWidth:350px;dialogHeight:100px;dialogleft:200px;dialogtop:200px;status:no;help:no;';
var respond = window.showModalDialog("login.aspx", this, '', style);
}
登录页面由用于用户名和密码的文本框以及用于登录按钮的按钮组成。检查数据库中的用户名和密码后,我的问题是如何使用代码隐藏 (.cs) 将值从弹出页面传递到父页面( bool 和字符串数据类型)。如果在将值传递给父页面后可能,如果 bool 值 = true,它将加载成员(member)页面。
提前致谢。
最佳答案
您能否将代码中的 bool 值公开为一个属性,然后您可以将其直接写入页面,即
window.returnValue = '<%=MyPublicProperty%>;'
当页面呈现时,该属性将只是任何其他 javascript 引用,即
window.returnValue = 'thePropertyValue';
因此模态对话框的返回类型将反射(reflect)后面代码中的内容
另一种变体是使用 ClientScript
对象将代码隐藏变量写入标记,以便客户端可以从模态对话框返回
ClientScript.RegisterClientScriptBlock(this.GetType(), "example",
string.Format("var codeBehindProperty = '{0}';", MyPublicProperty), true);
希望这是有道理的
编辑
要检索该信息,它应该是 showModalDialog 调用的返回值。所以在你的例子中
var respond = window.showModalDialog("login.aspx", this, '', style);
变量respond
将包含codeBehindProperty
。如果您要单步执行代码,则在打开模式时,执行将在 showModalDialog
处暂停。当它关闭时,执行将继续,然后返回值在父页面中可用。
关于asp.net - 如何将值从模态对话框传递到父页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17067749/