Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
How can I enable a text box on clicking a button?
firstly I insert the property readonly="true" to the textbox.
what code should i use to set the property readonly=false for the textbox when i click the button
 
OP's additional information moved from non-solution 3 below
i write this one in the click handler

txtID.Attributes("readonly", "false")

but no success :/
Posted 13-Nov-12 4:50am
Edited 13-Nov-12 14:10pm
Nelek63.2K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If your code is posting back then in the C# you can set ReadOnly = false. If you want to do it on client side I would recommend using jQuery and then you can do
 
$("#idOfTextBox").attr("disabled",false);
  Permalink  
Comments
Marcus Kramer at 13-Nov-12 10:23am
   
+5. I Wasn't thinking of web for some reason.
ryanb31 at 13-Nov-12 10:29am
   
Ha. Good point. I went back and looked and it was not tagged ASP.Net. It is so trivial in WinForms I assumed it must be the web.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

1) Add a click handler to your code behind and tie it to your Button control.
2) In the click handler, write something like YourTextBox.readonly = false
3) That's it.
 
Cheers.
 
Edit: After seeing your answer that this is a web app, See ryan's answer as the way to go.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

'//TextBox1 is disabled when form load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       TextBox1.Enabled = False
   End Sub
'//TextBox1 is enabled when you click on Button1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox1.Enabled = True
End Sub
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

This works great for me now
Thnx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       txt1.Disabled = True
 

   End Sub
 
   Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 
       txt1.Disabled = False
 
 End Sub
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

'//Or if you wanna switch between enable/disable,you can use CheckBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    TextBox1.Enabled = False
    TextBox1.BackColor = Color.Red
End Sub
 
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked = True Then
        TextBox1.Enabled = True
        TextBox1.BackColor = Color.Green
    Else
        TextBox1.Enabled = False
        TextBox1.BackColor = Color.Red
    End If
 
End Sub
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 PIEBALDconsult 110
3 Richard MacCutchan 105
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100