So I ran into a weird issue today involving databinding a value from a datareader to a standard TextBox control.
I was running a standard method like this which binds a value to a TextBox control but the value/resulting text in the label control appeared strange in that several words were repeated randomly through
MultiLine TextBox. Even stranger was when I would click inside of the textbox control giving it focus, the textbox value would correct itself on its own (sounds strange but it’s true).
Sub PopulateForm()
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
con = New SqlConnection(ConfigurationManager.ConnectionStrings("ATBConnectionString").ConnectionString)
cmd = New SqlCommand("p_EditATBFinding", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@OPEID", SqlDbType.VarChar).Value = txtOPEID.Text
Try
cmd.Connection = con
Using con
con.Open()
dr = cmd.ExecuteReader()
While dr.Read()
txtViolationDescription_Summary.Text = dr("ViolationDescription_Summary").ToString()
End While
End Using
Finally
con.Close()
End Try
End Sub
This is the approach which was causing the problem where the width of the TextBox was set to a certain pixel value.
<asp:TextBox ID="txtViolationDescription_Summary" runat="server" Height="195px" TextMode="MultiLine" Width="800px" />
By changing the TextBox width using columns instead, it corrected the problem.
<asp:TextBox ID="txtViolationDescription_Summary" runat="server" Height="195px" TextMode="MultiLine" Columns="131" Rows="8" />