How to open page in new tab using the response. redirect at asp.net

后端 未结 8 2221
太阳男子
太阳男子 2021-01-03 23:42

I want to open a new tab or a new page by using Response.Redirect in a button click handler. I\'m using a query string to pass some values. How can I open he pa

8条回答
  •  灰色年华
    2021-01-03 23:53

    I encountered this same problem today.

    Response.write didn't work for me, to solve it I used instead System.Web.UI.ScriptManager.RegisterClientScriptBlock.

    This is how your btnSave click event should be:

    protected void btnSave_Click(object sender, EventArgs e)
    {
        ...//some code to insert records
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "openModal", "window.open('NewQuote.aspx?val= "+ this.txtQuotationNo.Text+"' ,'_blank');", true);
    }
    

    NOTE: I'm using ScriptManager.RegisterClientScriptBlock because the button is inside an UpdatePanel, if that's not your case you should try:

    protected void btnSave_Click(object sender, EventArgs e)
    {
        ...//some code to insert records
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "openModal", "window.open('NewQuote.aspx?val= " + this.txtQuotationNo.Text + "' ,'_blank');", true);
    }
    

提交回复
热议问题