Solved

ASPX VB.Net TextBox Postback Not saving changes to TextBox

Posted on 2011-09-27
8
315 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
Independent Software Vendors: 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!

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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