Does asp:textarea exist?

Hello,

I’m getting the hang of asp:textbox, but what is the .NET declaration for a textarea?

Thanks,
Chris

asp:textbox and then set it to multiline, etc…

I found this example, but it seems like a little much for a simple textbox. If you don’t mind, let me know if there is a simpler way to implement a multiline textbox:

[size=3]

    // Create an instance of a TextBox control.
    TextBox textBox1 = new TextBox();
    
    // Set the Multiline property to true.
    textBox1.Multiline = true;
    // Add vertical scroll bars to the TextBox control.
    textBox1.ScrollBars = ScrollBars.Vertical;
    // Allow the RETURN key to be entered in the TextBox control.
    textBox1.AcceptsReturn = true;
    // Allow the TAB key to be entered in the TextBox control.
    textBox1.AcceptsTab = true;
    // Set WordWrap to True to allow text to wrap to the next line.
    textBox1.WordWrap = true;
    // Set the default text of the control.
    textBox1.Text = "Welcome!";
 }

[/size] Thanks!

Chris S.

Yep:

<!--...-->
<asp:textbox id="textarea" mode="multiline" runat="server"/>
<!--...-->

:slight_smile:

Oh, that’s way nicer. Thanks, folks!

Chris S.

No problem. :slight_smile:

Say, that multi-line looks good, but it still works like a textbox and doesn’t wrap or allow new lines by pressing enter.

What are the particular parameters to get those to apply?

Thanks,
Chris S.

textBox1.AcceptsReturn = true;
textBox1.WordWrap = true;

Thanks, Sara,

I’m still getting the structure of an ASP.NET web form down, so excuse me for not filling in the blanks. I tried to stick the above into the code (editing in the proper textbox name), and I got this error:

[font=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]

Invalid token ‘=’ in class, struct, or interface member declaration

What am I doing wrong here?

Thanks,
Chris S.
[/font]

Will you show the code that you are getting the error on?

// Insert page code here
	//
	 void SendEmail(Object s, EventArgs e) {
			 MailMessage objMail = new MailMessage();
			 objMail.From = "chris@impliedbydesign.com";
			 objMail.To = "chris@impliedbydesign.com";
			 objMail.Subject = company.Text;
			 objMail.Body = "The following e-mail was submitted through your online contact form:<br>
";
			    //objMail.Body += Request.ContactForm("comments");
			 SmtpMail.SmtpServer = "localhost";
			 SmtpMail.Send(objMail);
	 }

	 comments.AcceptsReturn = true;
	 comments.WordWrap = true;

	   protected void Page_Load(Object Source, EventArgs E)
		{
			if (IsPostBack)
			{
				ContactForm.Visible = false;

			}
		}

That is all the code-behind code for the page, and this is the html:

[font=&quot]

<asp:textbox mode="multiline" runat="server" cssClass="contact-comments" id="comments">

[/font]

Thanks,
Chris S.

I tried this out and it worked for me:

<asp:TextBox id=“comments” CSSClass=“contact-comments” runat=“server” Wrap=“true” TextMode=“MultiLine”></asp:TextBox>

it automatically accepted the Return key. Try this without the setting in the code-behind.

Sara, you’re a peach! Thanks, it worked perfectly!

Thank you,
Chris S.

My code in VB does not automatically recognize the returns entered in the text box. WordWrap works like this, but not returns. Any ideas?

My Email Code:

Sub SendEmail(s As Object, e As EventArgs)

         Dim objMail As New MailMessage()
         objMail.From = txtFrom.Text
         objMail.To = "info@steelsports.net"
         objMail.Subject = txtSubject.Text
         objMail.BodyFormat = MailFormat.Html
         objMail.Body = "<html><head><title>" & _
                 HttpUtility.HtmlEncode(txtSubject.Text) & _
                 "</title></head><body>"
				
         objMail.Body &= "<p>" & _
                 HttpUtility.HtmlEncode(txtBody.Text) & "</p>"

         objMail.Body &= "</body></html>"
         SmtpMail.SmtpServer = "localhost"
         SmtpMail.Send(objMail)
         lblResult.Text = "The email has been sent!  Someone will reply within 48 hours.<br />" & _
		 "Please feel free to join our forum, as your question may be answered there.<br /><br />"
 End Sub

My TextBox:

                    Questions or Suggestions:
                    <br />
                    <asp:textbox id="txtBody" runat="server" Width="440px" height="100px" Wrap="true" TextMode="MultiLine"></asp:textbox>

	

Assuming that “comments” has been declared somewhere, you need to set the attribute within a function. In the page load would work.

 protected void Page_Load(Object Source, EventArgs E)
{
       if (IsPostBack)
       {
	ContactForm.Visible = false;
        }else{ //only need to set it once per load
            comments.AcceptsReturn = true;
	 comments.WordWrap = true;
        }
}

Yes you can with HTML. Here what I have in my site.

You can view the actual application:
http://www.myasp-net.com/directory/linkdetail.aspx?id=218

Code:
<textarea id=“COMMENTS” name=“COMMENTS” Class=“textbox” cols=“45” rows=“7” onKeyDown=“textCounter(this.form.COMMENTS,this.form.remLen,200);” onKeyUp=“textCounter(this.form.COMMENTS,this.form.remLen,200);” onFocus=“this.style.backgroundColor=’#FFFCF9’” onBlur=“this.style.backgroundColor=’#ffffff’” runat=“server” />
<br />
<input class=“textbox” type=“text” name=“remLen” size=“3” maxlength=“3” value=“200” readonly> <span class=“catcntsml”>Char count</span>
<br />
<asp:RequiredFieldValidator runat=“server”
id=“reqComments” ControlToValidate=“COMMENTS”
cssClass=“cred2”
ErrorMessage = “Enter a comment!”
display=“Dynamic” />

Dexter Zafra

i have created 3 text box , 1 being the text box with multiline to act as a text area. I also added an submit button so user can click the button and display what they have inputed into the other 2 text box…my problem is how can i get the text area to go to the next line every time a user click submit…ex: textbox 1 =id lastname ; textboxt 2 = id fisrtname ; textbox 3 =id text area…and button id = submit…any help is greatly appreiciated

If I read your question correctly…

Try and add a vbCrLF in between lines.

textbox3.text = textbox1.text & vbCrLF & textbox2.text & vbCrLF

that did it thanks …

very very nice but;

<% if vb. net 2005 then %>

TextMode=“MultiLine”

<%end if%>
:rofl: