2.0: setting TextBox.Text

R

R.A.M.

Hello,
Could you help me plase? I need to set Text property of TextBox when
second page is displayed and active. On first page I have:
Birth date: <asp:TextBox ID="BirthDate" runat="server"
ValidationGroup="BirthDate" />
...
Session["BirthDate"] = BirthDate;
On second page I have:
<asp:Calendar ID="Calendar" runat="server"
OnSelectionChanged="Calendar_SelectionChanged" />
...
protected void Calendar_SelectionChanged(object sender,
EventArgs e)
{
if (Session["BirthDate"] != null)
((TextBox) Session["BirthDate"]).Text =
Calendar.SelectedDate.ToString().Substring(0, 10);
}
But it doesn't work - no visible result.
Could you tell me plase what's wrong? Thank you very much!
/RAM/
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Of course there is no visible result. You have kept a reference to a
TextBox object that is no longer used.

The controls of a page is created when the page is requested. Then the
page is rendered as HTML, and the controls used to do it are disposed.
If the page is requested again, new controls are created, used and disposed.

If you keep a reference to one of those controls, you will just be
holding on to an object that will never again be used to create a page.

Are you trying to change the value of an input field that is displayed
in a web page? Then you have to do it using Javascript. Pages are
requested from the server, and once they are sent to the browser there
is no connection between the browser and the server. You can't send
something from the server to a page that has already been sent to the
browser.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top