ASP.Net Open New Tab in Browser from CodeBehind

后端 未结 2 1656
醉话见心
醉话见心 2020-12-10 13:37

I need to open a browser tab from a link that is given to me by an asp.net code behind. Normally I would have a link and target=\"_blank\", but the link that I

相关标签:
2条回答
  • 2020-12-10 14:29

    You're looking for the Target property.

    0 讨论(0)
  • 2020-12-10 14:30

    If you have the data needed to create the link when generating the initial HTML, you can do something like this in the Page_Load event:

    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.OnClientClick="javascript:window.open('MyPage.aspx?Param=" + Param1.ToString() + "');";         }
    }
    

    If you're waiting for the PostBack to get the required data to build the link, you can send javascript down to the browser via the ScriptManager:

    protected void Button1_Click(object sender, EventArgs e)
    {
        //process whatever you need to to get Param1
        ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('MyPage.aspx?Param=" + Param1.ToString() + "');",true);
    }
    
    0 讨论(0)
提交回复
热议问题