.Net web :点击button后台打开新页面

Button 事件中如下代码:

             string uri = "../Dialogs/PrintDatas.aspx?Ids=";
             uri += "'"+setReturnStr()+"'";
             //string scriptStr = string.Format("<script type=text/javascript language=javascript> window.showModalDialog('{0}','details', 'dialogWidth:1000px;dialogHeight:500px;center:yes;resizable:yes;status:no;scroll:auto')</script>" , uri);
             string scriptStr = string.Format("<script type=text/javascript language=javascript> window.showModalDialog('{0}')</script>", uri);

             //Response.Write(scriptStr);
             Page.RegisterStartupScript("Startup",scriptStr);

报js 错误;分析一下 我们这时才注册客户端点击事件 ,不外乎因为传递的参数这时才生成数据 ,也可变一下顺序:页面初始化时 为button按钮注册onClientClick单击点击事件 参数从隐藏控件中取得(或直接访问服务端方法)

下面这个方法即可行:

button 事件 onClientClick 在 onClick 前执行。

             string uri = "../Dialogs/PrintDatas.aspx?Ids=";
             uri += setReturnStr();            
             string str = string.Format("showDetails('{0}');" ,uri);
             this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", str , true);

<script type="text/javascript" language="javascript">

       function showDetails(url)
     {     alert(url);
        var result;
     result = window.showModalDialog(url,"details","dialogWidth:1000px;dialogHeight:500px;center:yes;resizable:yes;status:no;scroll:auto");
       }   

</script>

你可能感兴趣的:(JavaScript,.net,Web,String,url,button)