C#Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
I dont' know how to disable a button when there is no text in a textbox an enable it the moment a character is enterd to textbox!!!!!!!!!
I use textChanged event but it doesn't work correctly.for example when I delete the text(I mean all characters in textbox) the button is enabled but after pressing a BackSpace it becomes disabled.
How can I overcome this problem?Is there any other events to control this?
or any other suggestions?
Try defining sub for text_changed event for textbox object which reacts to lenght of textbox object. Don't forget to set the AutoPostBack property of the TextBox to "True".
A solution in vb (page8.aspx with page8.aspx.vb as code-behind file) would be:
page8.aspx
Partial Class Page8
Inherits System.Web.UI.Page
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If Len(CType(sender, TextBox).Text) > 0 Then
Button1.Enabled = True
Else
Button1.Enabled = False
End If
Button1.Focus()
End Sub
End Class
sorry only after posting reply did i realize you're working on C#
I'm not familiar with exact code in C#, but the principle would be the same:
-create sub (void) for textbox object text-changed event that enables/disables button object
-activate postback for textbox