Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 20, 2012 12:03 AM by CPrakash82
Member
5 Points
55 Posts
Jun 13, 2012 05:32 AM|LINK
how to give enable and disable for @html.textbox in controller in mvc3.
My textbox code:
@Html.TextBox("txtIden1")
After click button, How can i disabled or enabled Textbox in controller.
Thanks.
All-Star
135214 Points
21692 Posts
Moderator
MVP
Jun 13, 2012 05:35 AM|LINK
sampath1750 How can i disabled or enabled Textbox in controlle
add a variable to enable or disable it.
with javascript, on window_onload , check the variable and disable the textbox.
Jun 13, 2012 05:44 AM|LINK
I wrote button click event code in controller, like below
@using(Html.BeginForm())
{
@Html.TextBox("txtCustomerFilter");
}
<button name="button" value="Submit">Save</button>
<button name="button" value="cancel">Cancel</button>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Customer(string button, customer customerInsert, FormCollection formvalues)
if(button == "Submit")
//Code
else
return View();
48 Points
15 Posts
Jun 13, 2012 06:21 AM|LINK
Try this:
@Html.TextBox("Field", Model.Field, new { @readonly = "true" })
Participant
1061 Points
226 Posts
Jun 13, 2012 07:01 AM|LINK
On button click event call javascript function
function demo() { document.GetElementByName("txtIden1").disabled="true"; document.GetElementByName("txtIden1").readonly="true";
or
document.GetElementByName("txtIden1").disabled="false"; document.GetElementByName("txtIden1").readonly="false";}
thanks for reading my post
160 Points
104 Posts
Jun 19, 2012 03:05 PM|LINK
If you can use html textbox that process is so easy.
In your controller you send enable status as string using ViewData["isAllowEnable"]";
then your view area use following textbox control
<input id="textbox1" type="text" style="display:@ViewData["isAllowEnable"]" />
18314 Points
2851 Posts
Jun 20, 2012 12:03 AM|LINK
The code you have implemented should work but in case if you are looking for a clean solution have a look at the below article.
http://blog.ashmind.com/2010/03/15/multiple-submit-buttons-with-asp-net-mvc-final-solution/
Thanks,
sampath1750
Member
5 Points
55 Posts
how to give enable and disable for @html.textbox in controller in mvc3
Jun 13, 2012 05:32 AM|LINK
how to give enable and disable for @html.textbox in controller in mvc3.
My textbox code:
@Html.TextBox("txtIden1")
After click button, How can i disabled or enabled Textbox in controller.
Thanks.
ignatandrei
All-Star
135214 Points
21692 Posts
Moderator
MVP
Re: how to give enable and disable for @html.textbox in controller in mvc3
Jun 13, 2012 05:35 AM|LINK
add a variable to enable or disable it.
with javascript, on window_onload , check the variable and disable the textbox.
sampath1750
Member
5 Points
55 Posts
Re: how to give enable and disable for @html.textbox in controller in mvc3
Jun 13, 2012 05:44 AM|LINK
I wrote button click event code in controller, like below
@using(Html.BeginForm())
{
@Html.TextBox("txtCustomerFilter");
}
<button name="button" value="Submit">Save</button>
<button name="button" value="cancel">Cancel</button>
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Customer(string button, customer customerInsert, FormCollection formvalues)
{
if(button == "Submit")
{
//Code
}
else
{
//Code
}
return View();
}
JamesChen_Ka...
Member
48 Points
15 Posts
Re: how to give enable and disable for @html.textbox in controller in mvc3
Jun 13, 2012 06:21 AM|LINK
Try this:
@Html.TextBox("Field", Model.Field, new { @readonly = "true" })
bkis1112
Participant
1061 Points
226 Posts
Re: how to give enable and disable for @html.textbox in controller in mvc3
Jun 13, 2012 07:01 AM|LINK
On button click event call javascript function
function demo() { document.GetElementByName("txtIden1").disabled="true"; document.GetElementByName("txtIden1").readonly="true";or
document.GetElementByName("txtIden1").disabled="false"; document.GetElementByName("txtIden1").readonly="false";}thanks for reading my post
Trần Lê Thành Trung
rajan_top1
Member
160 Points
104 Posts
Re: how to give enable and disable for @html.textbox in controller in mvc3
Jun 19, 2012 03:05 PM|LINK
If you can use html textbox that process is so easy.
In your controller you send enable status as string using ViewData["isAllowEnable"]";
then your view area use following textbox control
<input id="textbox1" type="text" style="display:@ViewData["isAllowEnable"]" />
CPrakash82
All-Star
18314 Points
2851 Posts
Re: how to give enable and disable for @html.textbox in controller in mvc3
Jun 20, 2012 12:03 AM|LINK
The code you have implemented should work but in case if you are looking for a clean solution have a look at the below article.
http://blog.ashmind.com/2010/03/15/multiple-submit-buttons-with-asp-net-mvc-final-solution/
Thanks,