I have two textboxes...on the textchanged event of one textbox, readonly property of other textbox gets defined...e.g. first textbox is retrieving data as add,update,delete...when the first textbox text is changed to update then & then only second textbox readonly property is set to false...Now the problem,I am facing is....whenevr first textbox text is add,delete,its working fine..& second textbox is fetching the correct data..but once first textbox data gets changed to update,second textbox data remain unchanged though its readonly property gets changed correctly..it shows the same data as it was showing the first time when first textbox was changed to update...but after that,its data is not changing...plz help..

Dani AI

Generated

Most common causes in ASP.NET WebForms: the TextChanged handler never posts back (AutoPostBack not set), Page_Load is overwriting the textbox on every postback, or a partial postback (UpdatePanel) isn’t refreshing the control. Also note the difference between ReadOnly and Enabled/Disabled: a disabled control does not post its value, while ReadOnly does. TextChanged only fires when the posted value differs from the previous value in viewstate, so the event can appear to “not run” if the control text is re-assigned too early.

Quick checklist and example (VB.NET WebForms):

  • Ensure the first textbox has AutoPostBack="true" and the TextChanged event is wired.
  • Do not reassign the second textbox in Page_Load on every postback; wrap initial setup in If Not IsPostBack Then.
  • If using an UpdatePanel with UpdateMode="Conditional", either make the textbox a trigger or call UpdatePanel.Update() after changing the value.
' markup: <asp:TextBox ID="txtMode" runat="server" AutoPostBack="true" OnTextChanged="txtMode_TextChanged" />
' markup: <asp:TextBox ID="txtValue" runat="server" ReadOnly="true" />

Protected Sub txtMode_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
    txtValue.ReadOnly = (txtMode.Text.Trim().ToLower() <> "update")
    If Not txtValue.ReadOnly Then
        txtValue.Text = FetchValueForUpdate() ' query or recompute here
    End If
End Sub

Relevant comments from the thread: ’s idea of persisting user edits helps in desktop apps; ’s Refresh() is a WinForms fix and not applicable to WebForms (use UpdatePanel.Update or a full postback instead). Useful debug steps: set a breakpoint in the TextChanged handler, or trace current values in Page_Load and the handler to see which assignment is overwriting the textbox. Useful details to show when diagnosing: Page_Load code, the two textbox markup (AutoPostBack and event wiring), any UpdatePanel markup, and the data-binding logic.

Recommended Answers

All 4 Replies

please send your code............so that any one can help you in better direction

Seems that you are not storing/saving the updated text. Either save it or store it in a String.
2 TextBoxes (use TextBox1 to type in commands)

Public Class Form1
    Private sUpdateOfTxt2 As String = "updating content" '// stores updated text of TextBox2.

    Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
        With TextBox2
            If .ReadOnly = False Then .ReadOnly = True '// set to True if False.
            Select Case TextBox1.Text.ToLower
                Case "add" : .Text = "adding content"
                Case "delete" : .Text = "deleting content"
                Case "update" : .ReadOnly = False : .Text = sUpdateOfTxt2
                Case Else : .Text = "standby mode"
            End Select
        End With
    End Sub

    Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
        With TextBox2
            If .ReadOnly = False Then sUpdateOfTxt2 = .Text '// set text to String for storing.
        End With
    End Sub
End Class

I don't really get what you meant, will be better if you can post the code like what prnvnkmr194 said. But I would suggest that you either haven't changed the "readonly" property of the 2nd textbox or haven't saved last progress. There is a chance that you got logical error as well.

I had similar problems trying to change the text on a button...
saveButton.Text = "Save"

I ended up adding the line...
saveButton.Refresh()

and my problem is resolved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.