?
Solved

text field entry -- not updating string

Posted on 2007-11-25
5
Medium Priority
?
188 Views
Last Modified: 2013-12-16
A bit puzzling ... is that I have a text entry field ::   TextBox.TestField  

as the aspx page load, there is db read of existing field data as follows:

if (rdr[0] != DBNull.Value)
    TextBox_TestField.Text = (string)rdr[0];

this works fine.

I edit that field, i.e. add / amend the field content.

Obviously want to save the amended details -- and then run a sql update scripte on that field... the sql update script is ok -- but the problem is that the TextBox_TestField does seemed to have changed -- so when posting to sql it keeps original loaded data, yet on-screen *web-page) I see the updated value.

Scatching my head on this one ... should be obvious to solve, but perhaps I need more caffeine !

Any help with this would be much apprieated.
0
Comment
Question by:amillyard
  • 2
  • 2
5 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1040 total points
ID: 20346656
can you show in which event you "update" the database?
and in which event you read it out to the text controls?
0
 

Author Comment

by:amillyard
ID: 20346676
Page_Load () -- for reading db content  (calls a db read procedure)

update starts from pressing 'update' button -- goes to a procedure which contains update routine.
0
 
LVL 19

Accepted Solution

by:
Limbeck earned 960 total points
ID: 20346685
do you check for a postback?

       if (!Page.IsPostBack)
        {
       //your code
       if (rdr[0] != DBNull.Value)
       TextBox_TestField.Text = (string)rdr[0];
       }
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1040 total points
ID: 20346701
then, that is the flaw.
when debugging, you will see that page_load comes BEFORE the button_click event.
you will have to skip in the page_load() any database reading when the page.IsPostback is true, and do it after the database update routine...

0
 

Author Comment

by:amillyard
ID: 20346738
wow - impressive, you are both 'spot on'.

added the :  if (!Page.IsPostBack) to isolate the page_load section.

I was getting slightly confused on this occassion with the postback I think -- as I was not using any obvious postback (i.e. drop-down lists requiring page refresh etc).

Just that once the db update was performed, there is a redirect command within the same procedure, which moves to another page automatically -- i.e.not refreshing the same page.

But, I think the point I need to understand from your advise that I should assume a postback is happening, even if not obvious.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question