Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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();
        }
Posted
Updated 22-Feb-15 23:05pm
v2

Opening pages in new tab of the browser is something you can not control...It depends on the browser and the end user preferences...
Actually Response.Redirect not even support target information...
You may use Response.Write to create a client side JavaScript code to open the link with a specific target, something like this:
C#
Response.Write("<script>window.open('Add_Items.aspx?TestID=1234','_blank');</script>");

Of course this code too, can't ensure opening in new tab only in new window...
 
Share this answer
 
Comments
vickycode4 23-Feb-15 5:31am    
int ID = Convert.ToInt32(e.CommandArgument.ToString());
Response.Write("<script>window.open('Add_Items.aspx?TestID="+ID ','_blank');</script>");

Passing the Id throug commandArgument, i wrote somthing wrong in above code?.
if possible how to set the page size like popup
Kornfeld Eliyahu Peter 23-Feb-15 5:33am    
You have some errors (missing quote and + signs):
Response.Write("<script>window.open('Add_Items.aspx?TestID=" + ID + "','_blank');</script>");

You can pass every property a normal window.open can get - including size...
vickycode4 23-Feb-15 5:49am    
+5
Kornfeld Eliyahu Peter 23-Feb-15 5:51am    
I hope you are understand that this code can not! ensure new tab, only new window...It is extremely important you understand that as tabbed-browsing is relatively new we have no support for it...
vickycode4 23-Feb-15 6:00am    
my problem is solved now, but in future reference which one is more recommended. and if possible please share the "window.open can get - including size". details.
Us this:

C#
string url = "Add_Items.aspx?TestID="  + ID;
 string fullURL = "window.open('" + url + "', '_blank' );";
               ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", fullURL, true);
 
Share this answer
 
Comments
vickycode4 23-Feb-15 5:15am    
Thank you. Its working
King Fisher 23-Feb-15 5:19am    
Welcome :)
Maciej Los 23-Feb-15 5:16am    
+5
King Fisher 23-Feb-15 5:18am    
Thanks maciej ;)
Kornfeld Eliyahu Peter 23-Feb-15 5:24am    
Wrong! It is only a new window...There is nothing in this code about tabs...It opens in a new tab only because the current configuration of the browser. On different machine with different browser of different user it will not...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900