模式窗体来模拟的MessageBox
模式窗体来模拟的MessageBox
//使用方法:建一个基页面,将下列函数复制过去,其它所有页面从基页面继承,在派生页面中按钮事件中就可以调用下面的函数
来源:互联网
http://netread.caotingna.com/item/gelu-gaoshou-jinlai-taolun-you__90652.aspx
//使用方法:建一个基页面,将下列函数复制过去,其它所有页面从基页面继承,在派生页面中按钮事件中就可以调用下面的函数
//在弹出窗口的aspx中<head></head>间加入以下代码:<base target="_self">
//弹出一个模式窗口
//url:弹出窗体地址
//width:弹出窗体宽度
//height:弹出窗本高度
//allowStatus:是否显示状态条
//allowScroll:是否显示滚动条
//refreshParent:返回时是否刷新父窗体
//refreshButtonID:保留不用,即为空字符串
public void CspOpenWindowModal (string url, int width, int height,string allowStatus,string allowScroll,bool refreshParent,string refreshButtonID)
{
string options="'dialogWidth="+width+"px;dialogHeight ="+height+"px;"+
"help=no;status="+allowStatus+";scroll="+allowScroll+"'";
if(refreshParent==true)
{
GetPostDoPostBackScript();
}
RegisterStartupScript(Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetPopupScriptModal(url, options, refreshParent,refreshButtonID) + "</script>");
}
protected string GetPopupScriptModal(string url, string options,bool refreshParent,string refreshButtonID)
{
string returnScript;
if(refreshParent==true)
{
returnScript="var w=window.showModalDialog(\"" + url + "\", '', " + options + ");__doPostBack('"+refreshButtonID+"','');";
}
else
{
returnScript="var w=window.showModalDialog(\"" + url + "\", '', " + options + ");";
}
return returnScript;
}
/************************************关闭窗体************************/
//关闭一个窗口
//refreshParent:是否刷新父窗体,对模式窗体无效,只能是false
public void CspCloseWindow (bool refreshParent)
{
RegisterClientScriptBlock(Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetCloseWindowScript(refreshParent) + "</script>");
}
protected string GetCloseWindowScript(bool refreshParent)
{
string script="";
if (refreshParent)
{
script = "window.opener.document.forms(0).submit();";
}
return script+"window.close();";
}
//弹出一个模式窗口
//url:弹出窗体地址
//width:弹出窗体宽度
//height:弹出窗本高度
//allowStatus:是否显示状态条
//allowScroll:是否显示滚动条
//refreshParent:返回时是否刷新父窗体
//refreshButtonID:保留不用,即为空字符串
public void CspOpenWindowModal (string url, int width, int height,string allowStatus,string allowScroll,bool refreshParent,string refreshButtonID)
{
string options="'dialogWidth="+width+"px;dialogHeight ="+height+"px;"+
"help=no;status="+allowStatus+";scroll="+allowScroll+"'";
if(refreshParent==true)
{
GetPostDoPostBackScript();
}
RegisterStartupScript(Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetPopupScriptModal(url, options, refreshParent,refreshButtonID) + "</script>");
}
protected string GetPopupScriptModal(string url, string options,bool refreshParent,string refreshButtonID)
{
string returnScript;
if(refreshParent==true)
{
returnScript="var w=window.showModalDialog(\"" + url + "\", '', " + options + ");__doPostBack('"+refreshButtonID+"','');";
}
else
{
returnScript="var w=window.showModalDialog(\"" + url + "\", '', " + options + ");";
}
return returnScript;
}
/************************************关闭窗体************************/
//关闭一个窗口
//refreshParent:是否刷新父窗体,对模式窗体无效,只能是false
public void CspCloseWindow (bool refreshParent)
{
RegisterClientScriptBlock(Guid.NewGuid().ToString(), "<script language=\"JavaScript\">" + GetCloseWindowScript(refreshParent) + "</script>");
}
protected string GetCloseWindowScript(bool refreshParent)
{
string script="";
if (refreshParent)
{
script = "window.opener.document.forms(0).submit();";
}
return script+"window.close();";
}
来源:互联网
http://netread.caotingna.com/item/gelu-gaoshou-jinlai-taolun-you__90652.aspx