Navigation

Search

Categories

On this page

Bad Text Inside a Databound TextBox Control
SQL Server PIVOT Function

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 405
This Year: 33
This Month: 14
This Week: 0
Comments: 17

Sign In
Pick a theme:

# Wednesday, February 22, 2012
Wednesday, February 22, 2012 1:53:15 PM (GMT Standard Time, UTC+00:00) ( ASP.NET )


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

Comments [0] | | #