Jad Chahine
Jad Chahine

Reputation: 7169

How do I Redirect a new Tab with Query String in asp.net

How to open new tab window with passing ID using Query String.

I tried all the possible ways,i.e Onclientclick and others. but not.help me.

Thank you in advance

if (e.CommandName == "Items")
        {
            int ID = Convert.ToInt32(e.CommandArgument.ToString());
            Response.Redirect("Add_Items.aspx?TestID=" + ID);
        }


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int id = Convert.ToInt32(Request.QueryString["TestID"]);
            lblTestID.Text = id.ToString();
        } 

Upvotes: 0

Views: 1044

Answers (1)

David
David

Reputation: 219087

The server-side code can't instruct the browser to open a new tab, that's not how redirects work. All a redirect does is tell the browser to navigate to an address.

To open a new tab, you'd need to use client-side code. Generally this could be as simple as:

window.open(address, '_blank');

However, keep in mind that browsers make no standard guarantee to open things in tabs vs. new windows. That's entirely up to the browser's settings and capabilities. (I think that in some browsers it might make a difference whether this code is executed directly or in a click event.)

Upvotes: 1

Related Questions