protected void Button5_Click1(object sender, EventArgs e)
    {
        try
        {
            //string strJS = "window.open('http://localhost/kidddd/photo/"+this.TextBox1.Text+"')";
            string strJS = "window.open('../../photo/" + TextBox1.Text + "')";
            this.Button5.Attributes.Add("onclick", strJS);
        }
        catch (Exception ex)
        {
            Response.Write(" <script language=javascript>alert('" + ex.ToString().Replace("'", @"\'") + "'); </script>");
        }
        
    }不要问我拿其他代码....因为我这段代码复制去哪里都是一样.....都是要点2次才有效
问题我大概知道...但是不知怎么改...请教...

解决方案 »

  1.   

    string strJS = "window.open('../../photo/" + TextBox1.Text + "')";
                this.Button5.Attributes.Add("onclick", strJS);把以上代码放在Page_Load中就只需要按一次了。
      

  2.   

    ClientScript.RegisterStartupScript(this.GetType(), "returnVal", "js() ;", true); 
      

  3.   

    要在Page_Load里邊初始化頁面的時候就加上客戶端的操作
      

  4.   

    Button5_Click1事件中你没有点击的时候,this.Button5.Attributes.Add("onclick", strJS);
    没有加载,当你点击第一次的时候,onclick事件注册上去了,所以点击第二次有用,
    在Page_Load事件中注册Button5的onclick事件。
      

  5.   

    Button5_Click1(object sender, EventArgs e)
    是你点击Button5这个按钮之后的事件
    this.Button5.Attributes.Add("onclick", strJS);
    是在代码里加上你写的脚本也就是说,当用户点击Button5之后
    页面上才会有strJS这个脚本
    所以当然要写2次了
      

  6.   

    8楼说的很对.你要在页面加载以后就加载BUTTON5的脚本.你放BUTTON5里.第一次点击事实上是加载.第二次才执行