2012年6月26日 星期二

{C#} WebForm出現彈跳視窗


//彈跳訊息後關閉視窗
public void SowAndClose()
{
    Page p = (Page)System.Web.HttpContext.Current.Handler;
    ClientScriptManager CSM = p.ClientScript;
    String ScriptName = "close";
    String ScriptMsg = "alert('我是訊息');window.opener = null;window.open('','_self');window.close();";
    Type CsType = p.GetType();
    if (!CSM.IsStartupScriptRegistered(CsType, ScriptName))
    {
        CSM.RegisterStartupScript(CsType, ScriptName, ScriptMsg, true);
    }
}

//直接關閉視窗
public void Close()
{
    Page p = (Page)System.Web.HttpContext.Current.Handler;
    ClientScriptManager CSM = p.ClientScript;
    String ScriptName = "close";
    String ScriptMsg = "window.opener = null;window.open('','_self');window.close();";
    Type CsType = p.GetType();
    if (!CSM.IsStartupScriptRegistered(CsType, ScriptName))
    {
        CSM.RegisterStartupScript(CsType, ScriptName, ScriptMsg, true);
    }
}

資料來源:
http://www.aspxpet.com/ArchiveHtml/2010/1/Article-2b73c5fa-9068-4f00-ae35-0065853a6111.html