1

你好朋友我写了一个在新窗口中打开一个aspx页面的代码。但是,当我第一次单击页面按钮时,它不会打开窗口,但之后每次单击时它都会打开。我的意思是说第一次单击asp.net中的按钮时没有打开窗口这是我的代码

 protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.OnClientClick =
  "window.open('ezychat/frmchathome.aspx?FromUserId=" +Session["User_userid"] +
                     "&Username=" + Session["User_username"] +
                    "&IsReply=yes','','width=400,height=200,scrollbars=no,toolbars=no,titlebar=no,menubar=no'); isLostFocus = 'true';";
    }

请告诉我为什么会这样

4

3 回答 3

0

因为在第一次单击时它会分配OnClientClick事件Button1并且不会将您重定向到 windows.open 事件,因为当您第一次单击此按钮时尚未执行声明。您必须OnClientClick在Event 上声明此pageLoad事件以在第一次重定向您时你按这个Button1

于 2013-06-25T04:16:52.443 回答
0

嗯..这将根据您的要求工作...也删除您的 onclick 事件...

protected void Page_Load(object sender, EventArgs e)
    {
        Button1.OnClientClick =
        "window.open('ezychat/frmchathome.aspx?FromUserId=" + Session["User_userid"] +
                           "&Username=" + Session["User_username"] +
                          "&IsReply=yes','','width=400,height=200,scrollbars=no,toolbars=no,titlebar=no,menubar=no'); isLostFocus = 'true';";

    }
于 2013-06-25T04:20:28.547 回答
0

您需要添加此代码

Button1.OnClientClick =
  "window.open('ezychat/frmchathome.aspx?FromUserId=" +Session["User_userid"] +
                     "&Username=" + Session["User_username"] +
                    "&IsReply=yes','','width=400,height=200,scrollbars=no,toolbars=no,titlebar=no,menubar=no'); isLostFocus = 'true';";

pageload方法而不是Button click事件中。

发生的情况是,在第一次单击时,您将属性设置OnClientClick为按钮,因此下次单击它时它会起作用。

于 2013-06-25T04:21:00.330 回答