473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

session problem with textbox text

asp.net, visual studio 2003, IE6
I have a sample web page that is linked to another page. On the first page,
I have a text box, on the second, the first page's text box text is displayed
using a session variable. This works fine. However, when I return to the
first page, the text box content is blank.
If, prior to going to the second page, I hit 'refresh', the text disappears.
If I add a button control to the page, and click it before refreshing the
page, the text will reappear in the textbox.
If I then go to the second page and then back to the first, the textbox is
again blank.
I have added another text box that displays an incrementing counter (ie:
each time the button is clicked, the number displayed goes up by one). This
displays exactly the same behaviour as the other text box, except it will
show the next number after displaying a blank on return to the page (after
clicking the button again).

The session variable seems to be working ok, so I suppose the problem lies
with how I am trying to get it to display the textbox text.

Here's the code (currently included in the button_click event, but works the
same in page_load):
If Not Page.IsPostBack Then
Session("textinput") = TextBox1.Text
TextBox1.Text = Session("textinput")
End If

any thoughts?
--
one door shuts, another closes . .
Jul 21 '05 #1
2 2496
I think its a logic error

Session("textinput") = TextBox1.Text
TextBox1.Text = Session("textinput")

Consider the case where the first page is reloaded after coming back from
the second page. Since it initially holds a String.Empty or "" upon first
initilization, your first line of code, overwrites the value in the Session
with "" (string.empty).

Then the second line tries to retrive the value back from the Session, but
the session now contains the updated value of "", so your textbox remains
empty!!

You should check the value of the TextBox before saving it to the Session
and only if its not "", then save it to session.
Regards,
Saurabh Nandu
[ www.AksTech.com ]
[ www.MasterCSharp.com ]

Jul 21 '05 #2
Yes, thank you. I changed it to:

If Not TextBox1.Text = String.Empty Then
Session.Contents("textinput") = TextBox1.Text
End If

and also put :

If Not Page.IsPostBack Then
TextBox1.Text = Session.Contents("textinput")
End If

into the page_load event (from the button_click where it was previously).
It now works fine.

Regards

David

"Saurabh Nandu" wrote:
I think its a logic error

Session("textinput") = TextBox1.Text
TextBox1.Text = Session("textinput")

Consider the case where the first page is reloaded after coming back from
the second page. Since it initially holds a String.Empty or "" upon first
initilization, your first line of code, overwrites the value in the Session
with "" (string.empty).

Then the second line tries to retrive the value back from the Session, but
the session now contains the updated value of "", so your textbox remains
empty!!

You should check the value of the TextBox before saving it to the Session
and only if its not "", then save it to session.
Regards,
Saurabh Nandu
[ www.AksTech.com ]
[ www.MasterCSharp.com ]

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Paul Yanzick | last post by:
Hello, I am trying to develop a book tracking application for my capstone in school, and am running into a problem. The application is an ASP.Net application written in C#. The first page you...
3
by: Tom | last post by:
Hi I have a web application using asp.net and c#. User has to login to the application with his username and pwd. However, I do not allow other user uses the same username and pwd to login, i.e....
7
by: TS | last post by:
I was under the impression that when you get a reference to an object, then update that reference, the object gets updated. Apparently this isn't the case using session? code (note at this point...
3
by: Chumley the Walrus | last post by:
I have a textbox control that represents a username in a password scheme, and I'm trying to turn the ID of the textbox control (the id = lgname ) into a session object. Doing lgname.text =...
3
by: Aaron | last post by:
Why do my session values return to nothing on post back? I want to click a button and have the row, as in: dataset.table(0).rows(THIS ROW NUMBER IS WHAT I AM TALKING ABOUT), either increment or...
2
by: TattyMane bigpond.net.au> | last post by:
asp.net, visual studio 2003, IE6 I have a sample web page that is linked to another page. On the first page, I have a text box, on the second, the first page's text box text is displayed using a...
2
by: Frank | last post by:
Can I do this? I add a session var in C# and ultimatly want to pass it into a vbscript client side activeX control. This is what I have so far but get " Object Required:'name2' " error. Can...
3
by: rn5a | last post by:
A ASPX Form has a TextBox & a Button. Users enter their username in the TextBox & submit the Form after which records pertaining to the username get retrieved from a MS-Access database table &...
8
by: adarshyam | last post by:
hi.. I am new to vb.net i am doing a program using dynamic textboxes which involves two pages .. where values of textboxes in one page must be transfered to to other sex of textboxes in another page,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.