Monday, January 17, 2011

Pass Values using queryString

Hi folks !!!!
Again guys this is also about web pages, do you ever wanted to pass a value from a page to another , this is the most fundamental way of doing it .
 So lets say you have a textBox  accepting name of the user , and you want to set that value to a label  in next page .

this is the simple way....

// hfCode is a hiddenField and txtLogin is my textbox, and Login ,code are my parameters.
Response.Redirect("URladdress.aspx?Login=" +
txtLogin.Text + "&Code=" +
hfCode.Value);

So in the receiving end  or the page all you have to do is ,

if (Request.QueryString["Login"] != null && Request.QueryString["Code"])
{
lblWelcome.Text = "Welcome "+ Request.QueryString["Login"]
+" "+
      Request.QueryString["Code"];
                   }


That's all,
Enjoy.

P.S. make sure to check that parameters are not null before accessing




No comments:

Post a Comment