Solved

ASPX VB.Net TextBox Postback Not saving changes to TextBox

Posted on 2011-09-27
8
303 Views
Last Modified: 2012-05-12
I have an application that calls a page with a text box for inputting notes into a database. The first time I call it when the text box is blank, type text and save it works fine.  When I call it a second time and it comes up with text and I add more text, it does not save the changes.  How do I get it to postback the changes prior to writing to the database?
0
Comment
Question by:sbdt8631
  • 4
  • 3
8 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36710181
Can you post the relevant code?
0
 
LVL 1

Author Comment

by:sbdt8631
ID: 36710686
See attached file.
Thanks
relevantCode.txt
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36710996
I see your redirecting to another page in your button click handler, so I am confused as to how you are calling this code a second time. Are you navigating back to this page at some later point in your application?

As a side note, your code is open for SQL injection. Any time you use string concatenation to build queries, especially when you are not validating input, you providing an attack vector for malicious users. Please consider using parameterized queries and ALWAYS validate the data coming from your users  = )
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36711004
P.S.

Your code is also open to cross-site scripting attack because of the lack of validation.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:sbdt8631
ID: 36711191
It is a private web site so I am not really concerned about security.
Yes I navigate back.  I click a url on a gridview and pass the item number to this page to post notes to the database.  When I do it the first time, it posts the initial note.  But when I try to add to the note on scend or third visits to this page it does not update the database with the new information added to the textbox.  I need a way to postback the contents of the textbox to the server prior to updating the database or whatever method I can use to capture the new text added to the textbox on further visits.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36711327
Have you stepped through the code to see if an exception is being raised? Also, are you certain that the item number is being passed correctly via the query string?
0
 
LVL 4

Accepted Solution

by:
manishkungwani earned 500 total points
ID: 36712308
I will suggest to write this code
        TysonItem3 = Request.QueryString("TysonItem2").ToString

Open in new window


as:

If Not (Page.IsPostback) Then
    TysonItem3 = Request.QueryString("TysonItem2").ToString
End If

Open in new window


This might resolve your issue, as otherwise the code seems fine ..
0
 
LVL 1

Author Closing Comment

by:sbdt8631
ID: 36712709
You were close.  I was rewriting my textbox back to the original database value on postback before I updated the database.  Thank you    

 Do While myReader1.Read
            If Not (IsDBNull(myReader1("notes"))) Then
                TextBox1.Text = myReader1("notes")
            End If
        Loop
becomes:
        Do While myReader1.Read
            If Not (IsDBNull(myReader1("notes"))) Then
                  If not(page.ispostback) then
                TextBox1.Text = myReader1("notes")
                  end if
            End If
        Loop
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now