Make HtmlTextArea Readonly on the fly

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
 
M

Martin Dechev

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.
 
T

Teemu Keiski

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)
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top