asp textbox not reflecting changed text on postback to server

M

moondaddy

Using vb.net 1.1, I have an asp textbox control on my aspx page. When the
page pops up, this textbox is already populated with data from the db. When
I edit the text and click on a submit button and then step through the code
behind on the server, I see that the textboxes Text property still has the
original text in it and not the text I keyed in. Can anyone explain what's
going on here and how I can resolve it?

Thanks.
 
S

Steven Cheng[MSFT]

Hi Moondaddy,

Thanks for posting here. From your description, you found the ASP.NET
TextBox's value not be updated with the user's input value when the page is
posted back. And you foudn this when debugging and look up in the
codebehind, yes?

As for this problem, I'd like to ask some further questions:
1. Do you meet this problem in only one page or it's a common issue on your
side?

2. Where did you add breakpoint to look up the TextBox's Text Property?
Since the Servercontrol's value will be update in thePostDataChangeEVent
which is before Page_Load and after page_Init, so if you look up in the
Page_Init
you'll found the TExtBox's TExt property remains the initial value , if you
looked up in the Page_Load event, I think this a bit strange.
Here is a reference on ASP.NET server control's exection lifecycle:
#Control Execution Lifecycle
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcontrolexecutionli
fecycle.asp?frame=true

3. Since I'm not quite sure on your detailed code logic in the certain
page. Would you please try create a simple page to repro this problem? If
so, we can try testing on our side and do some further research on it.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
M

moondaddy

Thanks I found the problem. I put break points in the Page_Init, Page_Load,
and the btnSubmit_Click events to watch the value of this textbox's Text
property. My problem was that in the btnSubmit_Click event is where I was
running the code to do something with the textbox's new text value, but in
the Page_Load event I had code that got data from the db to populate all the
textboxes values from the user's profile. The Page_Load event was happening
before the click event and therefore wiped out any new changes from the
browser. This was the reverse of what I expected to happen. My logic was
that the click event was what started the entire postback process from the
browser so I assumed it would happen first (similar to a winforms events),
and I thought that the page_load event would happen last as the page loads
back to the client. I had it mostly backwards and in this analysis I
discovered more errors in me process logic.

I see the light now.
 

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

Top