Get <TextArea> text

W

Wayne Wengert

Is there a way for ASP.NET/VB codebehind to get the contents of a plain old
<textarea> element? I added an id='myname' to the <textarea> tag but VSNET
complains that it is undefined?

Wayne
 
M

Mark Fitzpatrick

Wayne,
Did you also add the runat=server attribute?

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
W

Wilco Bauwer

You may want to use the <asp:TextBox /> control instead by the way, and
set its TextMode property to MultiLine. It'll then render a textarea,
and provide some additional functionality.
 
W

Wayne Wengert

Yes, I do have the runat="Server" - here is the actual tag:

<TEXTAREA runat="server" ID=holdtext STYLE="display:none;"></TEXTAREA>

I still get the " Name 'holdtext' is not declared." error.

Wayne
 
W

Wayne Wengert

Actually, that was my first approach but I have not been able to find a way
for jscript to select the text in a ASP.Net control. I need to select the
text in jscript to be able to copy it to a clipboard. I've googled and used
several jscript forums but no one seems to know how to do this?

Wayne
 
W

Wilco Bauwer

In/after the prerender phase of the life cycle of the page/control, you
can use the control's ClientID as a reference on the clientside.
 
W

Wayne Wengert

I'm sorry but I have no idea how to apply that information. How/where do I
execute code in/after the prerender phase?

Wayne
 
D

D.W. Warlock

Wayne, in your code behind, you need to make sure that the holdtext
variable is declared as a System.Web.UI.HtmlControls.HtmlTextArea
control. I'm not sure how this is declared in VB.NET (maybe a VB.NET guy
could help explain? C# guy here), but something along the lines of:

<code>
protected System.Web.UI.HtmlControls.HtmlTextArea holdtext;
</code>

in your Page's class declaration.

hth,
~d
 
W

Wayne Wengert

Thanks - makes sense. I'll pursue that

Wayne

D.W. Warlock said:
Wayne, in your code behind, you need to make sure that the holdtext
variable is declared as a System.Web.UI.HtmlControls.HtmlTextArea
control. I'm not sure how this is declared in VB.NET (maybe a VB.NET guy
could help explain? C# guy here), but something along the lines of:

<code>
protected System.Web.UI.HtmlControls.HtmlTextArea holdtext;
</code>

in your Page's class declaration.

hth,
~d
 
W

Wilco Bauwer

Override OnPreRender and use the control's ClientID when you render
some javascript. For example, say your script just displayed the
contents of the textbox in an alert() on the clientside, you could do
something along these lines:

[C#]
....
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string key = "myScriptKey";
if (!this.Page.IsStartupScriptBlockRegistered(key))
{
string functionCallScript =
String.Format("myJSFunction('{0}');", this.myTextBox.ClientID);
this.Page.RegisterStartupScriptBlock(key, functionCallScript);
}
}
[/C#]

[ASxX]
<script type='text/javascript'>
function myJSFunction(elementID)
{
var el = document.getElementById(elementID);
if (el)
alert(el.value);
}
</script>
[/ASxX]

In your case you can replace myJSFunction with a function which does
that copy to clipboard stuff you talked about.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top