如何在asp.net中打开新的浏览器窗口

如何在asp.net中打开新的浏览器窗口

问题描述:

先生

我希望当用户在asp .net中单击网格视图"的模板按钮时,应该打开一个新的浏览器.我已经完成了该项目,但是问题是,当我第一次单击按钮时,新窗口没有打开,而第二次单击时,它正在工作.您能解决这个问题吗?我已经在下面编写了代码.

Sir

I want that when a user click on template button of Grid View in asp .net a new browser should open. I have done the project but the problem is that when i am clicking on button for the first time new window is not opening and on second click it is working.Can you please solve the problem ? I have written the code below..

protected void gvEmployer_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        
        if (e.CommandName =="cmdDetails")
        {
            int index =Convert.ToInt32(e.CommandArgument);
            Button btn = (Button)gvEmployer.Rows[index].FindControl("btnDetails");
            btn.Attributes.Add("onClick", "window.open('detailsofjobseeker.aspx', '', '', 'height=200,width=400'); return false");
        }
      
    }

Sashibhusan Meher,

这是因为您需要一次将脚本注册到DOM,请尝试执行以下操作

在javascript函数中编写window.open代码
喜欢

hi Sashibhusan Meher,

This is because you need to register the script once to DOM, Try doing the below things

write the window.open code in a javascript function
like

<script language="javascript">
function popUp()
{
window.open('detailsofjobseeker.aspx', '', '', 'height=200,width=400'); return false;
}
</script>



然后在pageLoad()
这样写..



then in pageLoad()
write like this..

protected void Page_Load(object sender, EventArgs e)
        {
         String name1 = "PopupScript";
         String text1 = "<script type=\"text/javascript\">popUp();";
         RegisterStartupScript(name1, text1);
        }



并在通话时..这样写



and while calling.. write like this

btn.Attributes.Add("onClick", "popUp();");



它可能会起作用.

谢谢.



it may work.

Thanks.