In this article i will show you how you can disable all the controls by using only single line jquery code to disable all the controls present in your form or page. In this i have used html helper control and disabled it by using jQuery.
Now here is the code which is used for showing control on page.
@{ ViewData["Title"] = "Home Page"; } @using (Html.BeginForm("", "", FormMethod.Post, new { @id = "formcontrol" })) { <div class="text-center"> <h1 class="display-4">Welcome</h1> <p>@Html.TextArea("TextAreaControl", "", new { @class = "form-control" })</p> <p>@Html.TextBox("TextBoxControl", "", new { @class = "form-control" })</p> <p>@Html.Password("PasswordControl", "", new { @class = "form-control" })</p> <p>@Html.CheckBox("CheckBoxControl", false, new { @class = "form-control" })</p> <p>@Html.RadioButton("RadioButtonControl", false, new { @class = "form-control" })</p> <p><input type="submit" value="Submit" class="btn-danger" /></p> </div> } |
<script> $(document).ready(function () { $("#formcontrol :input").attr("disabled", true); }); </script> |
@{ ViewData["Title"] = "Home Page"; } @using
(Html.BeginForm("", "",
FormMethod.Post, new { @id = "formcontrol" })) { <div class="text-center"> <h1 class="display-4">Welcome</h1> @Html.TextArea("TextAreaControl", "", new { @class = "form-control
form-control-sm" })<br
/> @Html.TextBox("TextBoxControl", "", new { @class = "form-control form-control-sm" })<br /> @Html.Password("PasswordControl", "", new { @class = "form-control
form-control-sm" })<br
/> @Html.CheckBox("CheckBoxControl", false, new { @class = "form-control
form-control-sm" })<br
/> @Html.RadioButton("RadioButtonControl", false, new { @class = "form-control
form-control-sm" }) <p><input type="submit" value="Submit" class="btn-danger" /></p> </div> } <script src="~/lib/jquery/dist/jquery.min.js"></script> <script> $(document).ready(function () { $("#formcontrol :input").attr("disabled", true); }); </script> |
Download
0 comments:
Please let me know your view