Monday, March 26, 2012

Passing Variable to new Page

How do I pass a string to a new page.

For example I want to have a person enter their name and hit submit.
After hiting submit, the name is entered into a database and a confirmation page with the person's name is dislayed.

How do I do this?The simplest way, is with a querystring - -

response.redirect ("newpage.aspx?name=" & txtName.text)

Then, in the new page, just capture the querystring:

Dim sName as string
sName=request.querystring

From there, you can use the variable 'sName' anywhere you'd like on the page, as long as it's dimmed globally to the page (outside any events)
If u want the variable to be used only in one page Querystring is the best choice.If u want to hold the value for many pages, use Sessions.
Thanks,
Kumar.
Thanks. It's perfect.
Okay...I'm dumb..where do I declare the variable Dim strName?
I'm using Webmatrix. Do I delare them in the at the to of the html code or from the code section?

eg.<%declare here%>
in the code section...


Dim strName as string = Request.QueryString("Vari1")


HTH

0 comments:

Post a Comment