关闭模态窗口怎么样根据一个变量值来决定刷新还是不刷新父页面
public bool AutoPostBack
{
set
{
ViewState[ "AutoPostBack "] = value ;
}
get
{
if( ViewState[ "AutoPostBack "]==null)
{
return true;
}
else
{
return (bool)ViewState[ "AutoPostBack "];
}
}
}
private void Page_Load(object sender, System.EventArgs e)
{
WriteModalTree();
Button2.Attributes.Add ( "onclick ", "showModal(); ");
}
private void WriteModalTree()
{
StringBuilder sb=new StringBuilder ( " ");
sb.Append ( " <script language=\ "javascript\ "> \n ");
sb.Append( "function showModal()\n ");
sb.Append( "{\n ");;
sb.Append( "var returnValue=window.showModalDialog(\ " "+HttpContext.Current.Request.ApplicationPath+ "/WebForm2.aspx?module=111\ ",\ "\ " ");
sb.Append( ",\ "status:No;scroll:Yes;dialogWidth:750px;dialogHeight:550px;edge:raised;unadorned:Yes;resizable:Yes\ ");\n ");
sb.Append( "if(returnValue!=\ "undefined\ " && returnValue!=undefined) return false;\n ");
sb.Append( "}\n ");
sb.Append( " </script> ");
if(!this.Page.IsClientScriptBlockRegistered ( "showModalScript "))
{
this.Page.RegisterClientScriptBlock ( "showModalScript ", sb.ToString ());
}
}
如何根据 AutoPostBack 的值来决定刷新还是不刷新父页面呢
------解决方案--------------------模态窗口中:
<script>
var ret = ' <%=this.IsPostBack)? "1 ": "0 "%> '
window.returnValue = ret;
window.close();
父窗口
if(returnValue == '1 ')
{
//刷新
}
------解决方案--------------------你是哪个地方不明白呢?
一个变量的值你是怎么生成的呢?
AutoPostBack 是服务器端,你如果提交都会执行的。
你是根据AutoPostBack后返回给客户端的内容来来判断嘛?
在服务器端生成Response.Write( " <script> window.returnValue = ' " + 你的变量 + " ';window.close(); </script> ");
var returnValue=window.showModalDialog
这里的returnValue就是返回值,根据这个判断
------解决方案--------------------Button2.Attributes.Add ( "onclick ", "return showModal(); ")即可
showModal()函数里面返回true/false
------解决方案--------------------模态窗的细节要注意一下,
------解决方案--------------------学习 孟子E章
这个方法好 ....
学习
------解决方案--------------------javascript就是不好控制~