We help IT Professionals succeed at work.

How to add readonly attribute to a HTML text box programatically

Umamahez
Umamahez asked
on
1,360 Views
Last Modified: 2008-01-09
Hi experts,
how do we add readonly attibute to a htmltext box

i mean suppose I have a text box <Input id="MyTextBox" runat= "server" />
if i add <Input id="MyTextBox" runat="server" ReadOnly="readonly"/> manually it becomes raedonly.
I would like to know how to add this programatically.

i tried MyTextBox.Attributes["ReadOnly"] = "readonly";
did not work..
i tried
TextWriter tw = new StringWriter();
                  HtmlTextWriter myHtmlTextWriter  =
                        new HtmlTextWriter(tw);
                  myHtmlTextWriter.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.ReadOnly,read);
                  MyTextBox.Attributes.AddAttributes(myHtmlTextWriter);
did not work..
please help.
                  
Comment
Watch Question

Author

Commented:
sorry it works....I am just leaving the question for others to use.

Author

Commented:
It did not work, i need your help.
Cem TürkSenior Software Engineer

Commented:
myHtmlTextWriter.readOnly=true;

Author

Commented:
MyTextBox.Attributes.Add("ReadOnly",read);

Author

Commented:
sorry I did not see teh Attributes.add function.....taht is the answer

Author

Commented:
Experts:
I have answered the question myself.
The answer is MyTextBox.Attributes.Add("ReadOnly","true");
Please close this question.
Thanks
Umamahez
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.