Solved

text field entry -- not updating string

Posted on 2007-11-25
5
181 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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 260 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 240 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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 260 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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