Solved

ASPX VB.Net TextBox Postback Not saving changes to TextBox

Posted on 2011-09-27
8
311 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

790 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