c# - ReadOnly attribute does not work on TextBox -


i'm converting vs2003 vs2005 , part of conversion, need change way setting readonly attribute textbox controls.

we had following code before:

private void enablehistory(bool state) {   textbox itbnewhistory = ultrawebtab1.findcontrol("tbnewhistory") textbox;    if( itbnewhistory != null )   {      itbnewhistory.enabled = state;                                             itbnewhistory.readonly = ! state;   } } 

new code is:

private void enablehistory(bool state) {     textbox itbnewhistory = ultrawebtab1.findcontrol("tbnewhistory") textbox;      if( itbnewhistory != null )     {         itbnewhistory.enabled = state;         string hswitch = convert.tostring(!state);         itbnewhistory.attributes["readonly"] = hswitch;                                      } } 

also, removed readonly = "true" attribute asp.aspx code

with new code, readonly property true.

why happen , how can fix it.

thank you

the reason readonly because of way html works.

in html, merely presence of "readonly" (or "disabled) attribute makes readonly, if says readonly="false", still readonly because readonly attribute present.

if don't want readonly, have remove attribute if it's present, or don't add if it's not. also, actual value of readonly attribute should readonly so: readonly="readonly" not true or false.

itbnewhistory.attributes.remove("readonly"); if(state)     itbnewhistory.attributes.add("readonly", "readonly"); 

Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -