pass the control value from one web form to another form

  • Thread starter Thread starter tom
  • Start date Start date
T

tom

Hi Experts,

I want to pass the selectedDate value from my calender
form to another web form or a web user control. Could you
please show me how to do this?

Thanks in advance.
 
Tom,

There are a number of choices to do so.

Depending on your needs, you could use Server.Transfer or Response.Redirect
and the query string.

To use the query string

Response.Redirect("pagetwo.aspx?date=" & selectedDate.ToString)

Then on page two:

Dim Date As Date = CType(Request.Querystring.Item("date"), Date)

If you want to use Server.Transfer (Which would be more suited if a number
of variables need to be passed to the second page.) I suggest reading up on
it a bit more. It's fairly easy to do, but can be confusing for the user
because they are moved to page two but their browser's address bar will
still display the first page's url.

If you want some quick code samples I have some in the code library of my
web site: www.aboutfortunate.com. Just use the search box in the code
library area and input: "Server.Transfer".

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Here's a nice, simple way to pass values from one page to another:
(VB.NET code)

'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")

Then, in WebForm2.aspx:

'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)

Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx

http://www.aspalliance.com/kenc/passval.aspx

http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=600

http://www.dotnetbips.com/displayarticle.aspx?id=79
 
Hi Steve and S. Justin,

Thank you very much for your responses. I'm sorry that I
didn't explain my problem more clearly on my previous
mail. My problem is a different situation. On my page one
there is textbox and the page two only contains a calendar
control. I need to open page one first and click a button
on page one will open the page two. After user selected a
date from the calendar the page two will close and the
date should be shown on the page one's textbox. I'm
struggling with how to pass value back to page one when
the page one is already opened and update page one's data?

Please help me!
Thanks in advance.
 
Back
Top