By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,053 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,053 IT Pros & Developers. It's quick & easy.

Get <TextArea> text

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
It needs to have a runat="server" tag

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #2

P: n/a
Wayne,
Did you also add the runat=server attribute?

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #3

P: n/a
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.

Nov 19 '05 #4

P: n/a
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

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #5

P: n/a
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

"Wilco Bauwer" <wi****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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.

Nov 19 '05 #6

P: n/a
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.

Nov 19 '05 #7

P: n/a
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

"Wilco Bauwer" <wi****@gmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
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.

Nov 19 '05 #8

P: n/a
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
Wayne Wengert wrote:
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

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
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


Nov 19 '05 #9

P: n/a
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.

Nov 19 '05 #10

P: n/a
Thanks - makes sense. I'll pursue that

Wayne

"D.W. Warlock" <no*****@no.spam.org> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
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
Wayne Wengert wrote:
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

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
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 VSNETcomplains that it is undefined?

Wayne


Nov 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.