Make HtmlTextArea Readonly on the fly

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text area in which I have a client side javascript to process a "onclick". Because it is client side, I used a HtmlTextArea

<TextArea id="Summary" onmouseup="SumMouseUp()" style="WIDTH: 90%" name="Summary" rows="25" runat="server" /

Depending on the circumstance the user can sometimes edit the contents and at other time they cannot. There is a readonly parameter I can use at definition time

<TextArea id="Summary" onmouseup="SumMouseUp()" style="WIDTH: 90%" name="Summary" rows="25" runat="server" readonly /

but this is not "readonly=true" it is only "readonly" and in my VB codebehind I cannot set it

I tried using Summary.Disabled = True in the codebehind but this does not give me what I need since I have a "find" operation and when the textarea is disabled the user cannot see what is selected

How can I set this HtmlTextArea to ReadOnly on the fly (i.e., in the CodeBehind
 
Hi, Michael SL,

Supposing your identifier for the textarea in the Page class is textarea1
you will be able to set the readonly property in the following way:

[C#]
//set it
textarea1.Attributes["readonly"] = "readonly";
//reset it
textarea1.Attributes.Remove("readonly");

[VB.NET]
'set it
textarea1.Attributes("readonly") = "readonly"
'reset it
textarea1.Attributes.Remove("readonly")

Hope this helps
Martin
Michael SL said:
I have a text area in which I have a client side javascript to process a
"onclick". Because it is client side, I used a HtmlTextArea:
<TextArea id="Summary" onmouseup="SumMouseUp()" style="WIDTH: 90%"
name="Summary" rows="25" runat="server" />
Depending on the circumstance the user can sometimes edit the contents and
at other time they cannot. There is a readonly parameter I can use at
definition time:
<TextArea id="Summary" onmouseup="SumMouseUp()" style="WIDTH: 90%"
name="Summary" rows="25" runat="server" readonly />
but this is not "readonly=true" it is only "readonly" and in my VB codebehind I cannot set it.

I tried using Summary.Disabled = True in the codebehind but this does not
give me what I need since I have a "find" operation and when the textarea is
disabled the user cannot see what is selected.
 
Hi,

you can set the readonly attribute in codebehind by:

this.Summary.Attributes["readonly"]="readonly";

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


I have a text area in which I have a client side javascript to process a
"onclick". Because it is client side, I used a HtmlTextArea:

<TextArea id="Summary" onmouseup="SumMouseUp()" style="WIDTH: 90%"
name="Summary" rows="25" runat="server" />

Depending on the circumstance the user can sometimes edit the contents and
at other time they cannot. There is a readonly parameter I can use at
definition time:

<TextArea id="Summary" onmouseup="SumMouseUp()" style="WIDTH: 90%"
name="Summary" rows="25" runat="server" readonly />

but this is not "readonly=true" it is only "readonly" and in my VB
codebehind I cannot set it.

I tried using Summary.Disabled = True in the codebehind but this does not
give me what I need since I have a "find" operation and when the textarea is
disabled the user cannot see what is selected.

How can I set this HtmlTextArea to ReadOnly on the fly (i.e., in the
CodeBehind)
 
Marti

This works perfectly. Thank you very much

Michae

----- Martin Dechev wrote: ----

Hi, Michael SL

Supposing your identifier for the textarea in the Page class is textarea
you will be able to set the readonly property in the following way

[C#
//set i
textarea1.Attributes["readonly"] = "readonly"
//reset i
textarea1.Attributes.Remove("readonly")

[VB.NET
'set i
textarea1.Attributes("readonly") = "readonly
'reset i
textarea1.Attributes.Remove("readonly"

Hope this help
Marti
Michael SL said:
I have a text area in which I have a client side javascript to process
"onclick". Because it is client side, I used a HtmlTextAreaname="Summary" rows="25" runat="server" />>> Depending on the circumstance the user can sometimes edit the contents an
at other time they cannot. There is a readonly parameter I can use a
definition timename="Summary" rows="25" runat="server" readonly />>> but this is not "readonly=true" it is only "readonly" and in my V
codebehind I cannot set itgive me what I need since I have a "find" operation and when the textarea i
disabled the user cannot see what is selected
 
Back
Top