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 3:50am
Edited 13-Nov-12 13:10pm
Nelek42.3K
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 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 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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 963
1 Tadit Dash 270
2 Sergey Alexandrovich Kryukov 250
3 OriginalGriff 233
4 Peter Leow 180
0 Sergey Alexandrovich Kryukov 9,435
1 OriginalGriff 5,498
2 Peter Leow 4,230
3 Maciej Los 3,540
4 Abhinav S 3,353


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