hello. i am just trying to save a TextBox.Text value to a database, but
strangely, when the value is changed on the web form, the changes are
not recognized in the event where i try to save the information.
sample.aspx contents:
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" runat="server"
Width="560px" Height="512px" Wrap="True" TextMode="MultiLine">
</asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Save Changes">
</asp:Button>
</form>
sample.aspx.vb contents:
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim sQuery As String = "SELECT col1 FROM table1 WHERE id=100"
Dim sConn = ConfigurationSettings.AppSettings("sqlconnectionst ring")
Dim oConn = New SqlConnection(sConn)
oConn.Open()
Dim oCmd = oConn.CreateCommand()
oCmd.CommandText = sQuery
Dim oReader = oCmd.ExecuteReader()
oReader.Read()
TextBox1.Text = oReader("col1").ToString()
oReader.Close()
oConn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim sQuery As String = "UPDATE table1 SET col1='" + _
fixer(TextBox1.Text) + "' WHERE id=100"
Dim sConn = ConfigurationSettings.AppSettings("sqlconnectionst ring")
Dim oConn = New SqlConnection(sConn)
oConn.Open()
Dim oCmd = oConn.CreateCommand()
oCmd.CommandText = sQuery
oCmd.ExecuteNonQuery()
oConn.Close()
End Sub
Function fixer(ByVal datainfo)
If datainfo <> "" Then
fixer = Replace(datainfo, "'", "''")
End If
End Function
the Page_Load event works just fine. the data is queried from the
database, and is populated into TextBox1. let's say, for example, the
data is the following string (in TextBox1):
Hello Everyone. This is a String.
the problem is as follows. let's say i modify this string to the
following example:
Hello. String.
then i click Button1. i would expect the database to be updated with
the new TextBox1.Text value, which should be "Hello. String." however
the value that gets sent during the Button1_Click event to the database
is the ORIGINAL value:
Hello Everyone. This is a String.
why does the TextBox1.Text property not change when i modify the text
inside of it? is there a different property i should be using to get at
the actual, visible text in a TextBox?
thanks for any help, i'm sure it's a silly question.
jason