Disable a button in asp.net MVC

3338
Views
1
Answers

How to disable a button in MVC view?

edit | flag
William Patrick
Asked on: Jun 16, 2011 at 6:49AM

1 Answers

14
2
14

You can disable a button in two ways

  1. Jquery
  2. Jquery and controller action

If you need to disable any control using some condition in controller action consider the below code

In the controller.

public ActionResult MyAction() {
 
ViewData["disablecontrols"] = false;
 
if (condition)
 
{
   
ViewData["disablecontrols"] = true;
 
}
 
return View();
}

and in the view

$(document).ready(function() {
var disabled = ;
 
if (disabled) {
    $
('input,select,button').attr('disabled',disabled);
// input for textboxes, select for Dropdowns
 
}
})

To disable a control by jQuery

$(document).ready(function() {

    $
('input,select,button').attr('disabled',disabled);
// input for textboxes, select for Dropdowns    

});

edit | flag
Gokul A
Answered on: Jun 16, 2011 at 8:27PM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags