Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How passing data from one Form to another ?

Status
Not open for further replies.

vilrbn

Programmer
Oct 29, 2002
105
FR
Hello,

Do you know how to access a control from one form to another.

I need to send a date coming from a calendar in Form2 to a textbox in my Form1 when Form2 is closed.

Can you help me ?
Thanks.

 
Vil. I think the preference on these boards to date is to use a QueryString in the URL, versus Session State which can become problematic when scaling your site. In your Response.redirect statement opening up Form1 you need to pick up your date and send it on over to Form2. Here's a tidbit of code for you if it might help.

'first capture your date in a textbox (or a declared variable, etc)

Sub calSelectChange(Sender as Object, e as EventArgs)
txtSampleDate.Text = calDateToUse.SelectedDate
End Sub

Next, include it in your Response.redirect to your Form2, e.g.,

Sub mybutton_Click(Sender as Object, e as EventArgs)
Response.redirect("\mypage.aspx?mydate='" & txtSampleDate.Text & "'")
End Sub

..something along those lines. Other State management techniques are available but there seems to be a preference here to use the Querystring.

Once on Form2 you just call the date:

Dim myDate As Date = Request.Querystring("mydate")

...and that's it.

 
Hi
I take it you don't mean closed - you want to redirect to the form1 when form2 gets submitted?

In that case, check out thread855-378759

Otherwise, if you are looking at doing some client side stuff with a popup window or something, check out thread855-331715

If neither of these answer your question, please let me know

Mark [openup]
 
Hi Isadore - dates are definitely one of those areas where you will need a server.urlencode to get it into the querystring without causing a problem - they are likely to contain / or \ characters; check out Thread855-378759
Mark [openup]
 
In fact I am opening a Form2 having a Calendar and once a date has been selected and Form2 is closed, I have to store the date back in a Textbox (txtDate) of Form1.

Finally I solve the problem using:

Response.Write(&quot;<Script Language='Javascript'>window.close();</script>&quot;)
Response.Write(&quot;<Script Language='Javascript'>window.opener.document.all(&quot;&quot;txtDate&quot;&quot;).value='&quot; & varDate & &quot;';</script>&quot;)
Response.Write(&quot;<Script Language='Javascript'>window.opener.focus();</script>&quot;)

on the Close event of my Form2 button.

Thanks for your help !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top