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次才有效
问题我大概知道...但是不知怎么改...请教...
this.Button5.Attributes.Add("onclick", strJS);把以上代码放在Page_Load中就只需要按一次了。
没有加载,当你点击第一次的时候,onclick事件注册上去了,所以点击第二次有用,
在Page_Load事件中注册Button5的onclick事件。
是你点击Button5这个按钮之后的事件
this.Button5.Attributes.Add("onclick", strJS);
是在代码里加上你写的脚本也就是说,当用户点击Button5之后
页面上才会有strJS这个脚本
所以当然要写2次了