Get <TextArea> text

  • Thread starter Thread starter Wayne Wengert
  • Start date Start date
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
 
Wayne,
Did you also add the runat=server attribute?

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
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.
 
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
 
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
 
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.
 
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
 
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
 
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
 
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.
 
Back
Top