asp 模态窗口的案例

 

在B/S结构中通常单一的使用页面的话会很单调的,添加一个按钮使窗体成模态窗口呈现。

 

实例:vs2010    sql2008

   /// <summary>
    /// 点击按钮弹出窗体
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        string url = "Default2.aspx";
        //ShowModelWindow(url,315,800,100,100,this.Page);      固定窗口的大小
        ShowModelWindow(this.Page,url);
    }

 

    /// <summary>
    /// 显示模态窗口,不固定窗口的大小
    /// </summary>
    /// <param name="p">导航页面地址</param>
    /// <param name="url">要想显示的模态窗口地址</param>
    public void ShowModelWindow(Page p, string url)
    {
        string csname = "ShowModelWindowScript";
        Type cstype = p.GetType();
        ClientScriptManager csm = p.ClientScript;//客户端脚本

        if (!csm.IsStartupScriptRegistered(cstype, csname))
        {
            string cstext = string.Format("<script language=javascript>window.open('{0}','newwindow','height=700,width=800,top=1,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,titlebar=no,status=no');</script>", url);
            csm.RegisterStartupScript(cstype, csname, cstext, false);
        }
    }

 

    /// <summary>
    /// 打开模态窗口以任意大小
    /// </summary>
    /// <param name="p">导航页面地址</param>
    /// <param name="url">要想显示的模态窗口地址</param>
    /// <param name="height">高</param>
    /// <param name="width">宽</param>
    /// <param name="top">据顶部距离</param>
    /// <param name="left">据坐距离</param>
    public  void ShowModelWindow(string url, int height, int width, int top, int left, Page p)
    {
        string csname = "ShowModelWindowScript";
        Type cstype = p.GetType();
        ClientScriptManager csm = p.ClientScript;

        if (!csm.IsStartupScriptRegistered(cstype, csname))
        {
            string cstext = string.Format("<script language=javascript>window.open('{0}','newwindow','height={1},width={2},top={3},left={4},toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,titlebar=no,status=no');</script>", url, height, width, top, left);
            csm.RegisterStartupScript(cstype, csname, cstext, false);
        }
    }

 

实现效果:

asp 模态窗口的案例_第1张图片

你可能感兴趣的:(String,object,脚本,url,asp,button)