Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Disabling button asp .net - using javascript

Currently in my application I am having a button and a text box. The user types something in the textbox and then presses the button. What I want is that:

The search button should should stay disabled when the page loads for the first time. I can achieve that by setting it to disabled in the code behind file.

Now I want it to remain disabled when the user types upto 2 characters. The moment the user types third character the button should get enabled automatically.

The important thing is that it has to be done without asp .net AJAX since this website will be run from old mobile phones. So only pretty basic javascript or jquery is supported.

Any help will be appreciated.

Thanks

Varun

like image 381
Varun Sharma Avatar asked Sep 29 '11 20:09

Varun Sharma


People also ask

How we can disable button in JavaScript?

To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .

How do I disable a button in webform?

If you just want to disable it and nothing else, then add attribute Enabled = "false". ImageButton1. Enabled = false; If the form is located in the master page, then you'll have to access that control from the content page via code behind and set the Enabled attribute.

Which method is used to disable a button?

In UI Dialog box, button as default class called ui-button so focus on it. Create a function that should trigger dialog box in ready that is on page load. Then use jQuery method prop('disabled', true) to disable that button with class ui-button.


1 Answers

in order to use the document.getElementById in asp.net and not have to use the full name, you should let asp.net provide it. Instead of: document.getElementById("ctl00_ctl00_phContent_phPageContent_btnSearch")

Try:

document.getElementById('<%= btnName.ClientID %>')

Where btnName is the asp:Button Id. The <%= code will generate the actual button id, fully qualified, so you don't have to worry about things changing with the hard coded id.

like image 58
Joel WZ Avatar answered Oct 20 '22 08:10

Joel WZ