1,新建一个用户控件,这里面要封装弹出窗口的界面
里面有个div id="xxx"
string strScript = xxxx.InitConfirmDialogScriptCode("#popUpMessageWindow", strTitle, 700, 700, strBtnText);
封装一段弹出窗口的代码
public static string InitConfirmDialogScriptCode(string strTarget, string strTitle, int intWith, int intHeight, string strBtnConfirm = "")
{
//弹出窗口生成函数
StringBuilder csText = new StringBuilder();
//添加脚本标签
csText.Append("<script type=\"text/javascript\"> ");
//添加函数
csText.Append("$(function () {");
csText.Append("try{");
//添加对话框
csText.Append("var window = $(\"" + strTarget + "\").dialog({ ");
//设置对话框属性
csText.Append(" modal: true, resizable: false,title:\"" + strTitle + "\",width:" + intWith + ",height:" + intHeight + ",buttons:{\"" + strBtnConfirm + "\":function(){ $(this).dialog(\"close\"); }} ");
//关闭函数即标签
csText.Append(" });");
csText.Append("window.parent().appendTo(jQuery(\"form:first\")); ");
csText.Append("}catch (e) { }");
csText.Append("});");
csText.Append("</script>");
return csText.ToString();
}
2,在用户控件的page-load中,调用Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "PopUpWindow", strScript);
往客户端动态加载javascript,其中strScript是你用函数返回的javascript string