Friday, March 16, 2012

passing a variable from page to page

I am working on a web app that takes a selection from a dropdown and uses the selection name to pass to the next page. I would like to know how to do this. When the selection is made, the user would press a button to pass the var and display the next page.

I need to know what to do on the first page and the how to accept the var on the second page.In the button's onclick event

onClick="document.location.href='pagename.aspx?selval=' + document.getElementById('ddl1').options[document.getElementById('ddl1').selectedIndex].value"
My next question is how do I define the var in the next page to use it.
What would the code look like?
To send value from one form to another:

Response.Redirect("Page2.aspx?abc="+dropDownList1.SelectedItem.Text );

to Receive the value in another page:

string sValue= Convert.ToString(Request.QueryString["abc"]);

Best of Luck.

-Rajib
Thanks, that worked out great!!!
Request.QueryString will return a string.

0 comments:

Post a Comment