开发者

How to Enable or disable textbox based on condidtion

          <%= Html.TextBox("txtWeight", EmployeeInformation.Weight, new { style = "font-family:Verdana;font-size:9px;", @onfocus = "this.value=''", @onmouseover = "jsWeight()",  @readonly= (ViewData["flag"].ToString().CompareTo("true")==0 ? true : false) })%>

or

           <%= Html.TextBox("txtWeight", EmployeeInformation.Weight, new { style = "font-family:Verdana;font-size:9px;", @onfocus = "this.value=''", @onmouseover = "jsWeight()",  @readonly= ViewData["flag"].ToString()) })%>

The above code I m using to display information in textbox, as you can see I m using a onFocus and onMouseover so that I can show data in t开发者_如何学编程ooltip, and I m using @readonly to make sure textbox can be or cannot be edited based on condidtion. But this is not working for me. I have checked viewData's value that is ok.It is as I m passing to it. I have tried using Disable as well but when I m using Disabled I get the value as disabled every time and when I m using disable my on foucs event is not working


You can't rely on @readonly and @disabled as they essentially make fields readonly or disabled simply by being present. Although the correct syntax should be:

<input readonly="readonly" />
<input disabled="disabled" />

The same result can be achieved with:

<input readonly="" />
<input disabled="" />

Or simply:

<input readonly />
<input disabled />

It's better to omit these attributes completely if you don't want the fields to be readonly or disabled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜