Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can we use querystring in server.transfer?help?
Posted

Yes we can.

I tried this and it worked.

default.aspx.cs
C#
protected void Page_Load(object sender, EventArgs e)
   {
       Server.Transfer("DEfault6.aspx?id=5");
   }



default6.aspx.cs
C#
protected void Page_Load(object sender, EventArgs e)
    {
        string s = Request.QueryString["id"] as string;
    }




an the value of s was 5 after i ran it.
 
Share this answer
 
Comments
Member 9027346 27-Jun-12 8:10am    
Thanks:)
Rahul Rajat Singh 27-Jun-12 8:12am    
you are welcome.

P.S. I think your other question similar onewith the cross page also has an answer. for that question if it worked then please mark the answer as solution as this would let other know that the problems is solved and the others with similar problem can also refer and benefit from it.
vangapally Naveen Kumar 27-Jun-12 8:20am    
Good Answer 5+
You cannot pass new querystring in Server.Transfer.
The Transfer method preserves the QueryString and Form collections. Thus if any existing querystrings were there then it will pass on.

Refer: MSDN: HttpServerUtility.Transfer Method (String)[^]

UPDATE: As Rahul already tested it out, it looks like one can pass querystring in Server.Transfer even though documentation does not states so. But, to it, I am sure URL will not change in the browser.
 
Share this answer
 
v2
Comments
Rahul Rajat Singh 27-Jun-12 8:00am    
I beg to differ here. try the code in my solution. it will work.

The real question is should we do this. and the answer to that would be no.
Rahul Rajat Singh 27-Jun-12 8:03am    
The only thing is that the USER will never be able to pass this query string from browser. as the browser url is not changed in user browser.
Sandeep Mewara 27-Jun-12 8:12am    
Thanks. Good to know. Updated answer to point it out.
Rahul Rajat Singh 27-Jun-12 8:15am    
you are welcome. and yes you are right the URL will not change.

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