Solved

ASPX VB.Net TextBox Postback Not saving changes to TextBox

Posted on 2011-09-27
8
306 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 75

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 75

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 75

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 75

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 IIS and Windows Authentication to SQL 21 52
Syntax error 9 45
Need a starter for ETL protocol? 4 31
Get Client IP on RDS - VB.NET 15 10
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

947 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

23 Experts available now in Live!

Get 1:1 Help Now