Solved

enable button control with textbox textchanged event

Posted on 2013-12-03
4
631 Views
Last Modified: 2013-12-04
Below is code for trying to change a button control for button.enabled = true and false depending on condition.  I am trying to changed the enabled state of the button control when the text in a separate text box changes.  When called the code fires but nothing happens on the page.

Can anyone help?

Thanks,

Protected Sub DataEntry1_TextChanged(sender As Object, e As EventArgs) Handles DataEntry1.TextChanged

        If Not IsNumeric(DataEntry1.Text) Then
            EnterDataBtn.Enabled = False
            ViewState("BtnEnabled") = False
        Else
            EnterDataBtn.Enabled = True
            ViewState("BtnEnabled") = True
        End If

    End Sub
0
Comment
Question by:rckrch
4 Comments
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 167 total points
ID: 39694222
Try removing the ViewState lines. I just tried it and the button was disabled fine without them.  Also, try removing the numeric check just to see if you are able to disable the button on the text changed event (which worked fine for me).  If so, then the problem is probably that you are taking the other branch of the if-then-else statement then the one you expect.
0
 
LVL 27

Assisted Solution

by:Chinmay Patel
Chinmay Patel earned 167 total points
ID: 39694612
Also this will cause a PostBack I suggest you either take it to client side or use AJAX. What are you trying to achieve? if it needs to be server side validation I will strongly suggest to use AJAX so that user doesn't see a Postback.
0
 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 166 total points
ID: 39694630
hi..

Try with Postback property of a textbox equal to true. It's working.
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 39694754
in the aspx page set the property AutoPostBack=true
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now