Solved

ASPX VB.Net TextBox Postback Not saving changes to TextBox

Posted on 2011-09-27
8
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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