Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2008, 05:53 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default How to assign a value to a Textarea

Hi there can any one tell me how can i acive the following:
I have a textarea in a webform and i need to populate the area with text from a doc file or any file type that will show on page load,
the other thing is that i would like to take the name from a textbox on the form and insertit into the textarea like
(dear sir/madam [value from the textbox] i am pleasd...)

i olso nedd to be abel to change the textarea content by a click event.



any help is appreciated
__________________
bx
 
Old December 19th, 2008, 09:56 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I am not sure if i understand you.

Your webform should look something like this:

Code:
<asp:TextBox id="textBox" runat="server" />
<br />
<asp:TextBox id="textArea" runat="server" MultiLine="true" Rows="5" Columns="10" />
In your .cs (or .vb) file you would do something like this to populate the textarea:


c# Code:
private void Foo()
{
   textArea.Text = String.Format("(dear sir/madam {0} i am pleasd...)", textBox.Text);
}

and to clear it you would do

c# Code:
private void FooTwo()
{
   textArea.Text = String.Empty;
}

Lastly, if this textarea is literally an HTML TEXTAREA tag you need to add the "runat=server" attribute to the tag so that it can be accessed in your code file and you will access the text via the Value property. So

c# Code:
textArea.Value = String.Empty;

//instead of

textArea.Text = "Foo";

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 19th, 2008, 10:25 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

Thanks for the replay , can you post the vb version please

what about geting only the first word in the textbox

thanks
__________________
bx
 
Old December 19th, 2008, 11:27 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The vb version is almost identical:

vb Code:
Private Sub Foo()
textArea.Text = String.Format("(dear sir/madam {0} i am pleasd...)", textBox.Text)

'or

textArea.Text = String.Empty

'or

textArea.Value = String.Empty;
End Sub

First off, this code:

vb Code:
textArea.Text = String.Format("(dear sir/madam {0} i am pleasd...)", textBox.Text)

will insert the string: (dear sir/madam <textbox> i am pleased...) into the textarea. <textbox> in the previous sample would be replaced with whatever text is in the textbox control. So if, for example, i typed Foo into the textbox the string that would be inserted into the textarea would be: (dear sir/madam Foo i am pleased...)

As far as getting the *First* word from the textbox that will depend on what you define as the first word. Does the first space between words define the first word? Does the first word in a hypenated word count as the first word or is the entire word the first word? So on and so forth.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 19th, 2008, 11:56 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

thanks Doug

the first word i ment like:[textbox.text=" Jon Smith"] i want just the name Jon and format it to look like

Dear Jon

I i am pleased...

if that is posible

thanks


bex
__________________
bx
 
Old December 19th, 2008, 12:13 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I would approach this situation in a different manner based upon my observation of what it is you are trying to do.

Trying to personalize messages (or any correspondence with the user for that matter) coming out from your site is a great idea but it needs to be done properly. From what I have gathered is that you are asking the user to supply their name into the Textbox on your form and you want your personalization to be based on that value, correct?

If you form looks something like this:

Name: <textbox>
Address: <textbox>
etc.

There are a slew of possible answers you can get for the name field: first name, first name and last name, nick name, and so on. For the sake of argument, lets assume that it is implied that the user is to supply their first name and last name for this field.

So if i were to put in Doug Parsons as the value for the Name field you can make the assumption that my first name is Doug so you could split the string based upon spaces to retrieve only Doug. Simple enough right? Well what if I supplied my name as: Do ug Parsons? If you split the string based upon spaces, you would return 'Do' as my first name which is incorrect and would look like poor craftsmanship if I were to get an email that says: Dear Do as opposed to Dear Doug.

To combat this I will typically have both a first name and last name field on my forms and use whatever value the user supplies as their first name as the value for correspondence, regardless of what is in there. If i don't care about first name and last name I will simply provide a name field and use the contents of that field for personalization.

If you are bound and determined to do proceed in the manner as you have implied you will want to look into string functions such as Split(), Substring(), and so on.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 19th, 2008, 12:47 PM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

You are right to have 2 textboxes 1 for the name and the other for the surmame that does make sense but i wasn't thinking,

now i have to look into the Split(), Substring(),


thanks
__________________
bx
 
Old December 19th, 2008, 12:53 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Looking into Split(), Substring(), and the other string manipulation functions is good for reference but I don't see where it will be applicable here.

This code:

vb Code:
textArea.Text = String.Format("(dear sir/madam {0} i am pleasd...)", textBox.Text)

would become something like:

vb Code:
textArea.Text = String.Format("(dear sir/madam {0} i am pleasd...)", textFirstName.Text)

which would insert the value of the First Name textbox into your string.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 20th, 2008, 10:23 AM
bex bex is offline
Friend of Wrox
 
Join Date: Aug 2008
Posts: 154
Thanks: 7
Thanked 1 Time in 1 Post
Default

the thing is that i need to prersent to the user a template document in the textarea that looks like a letter format,
(there is no need for the user to edit the content of the text box, it does not have to be a textarea it can be any controll that can pull data from a txt file.

with the txtArea.text=String.Format is working fine but i need to insert a paraghraph after the:txtName.Text so it will split the string to look like :
textarea.Text = String.Format("(Dear Mr {0}<p>here i Am plaesed to )", ltxtname.Text)

Dear Jon

I am .......

Kind Regards

is there a way to do this so i can asign the text to the controll via a web browser


bex
__________________
bx

Last edited by bex; December 20th, 2008 at 10:38 AM..
 
Old December 21st, 2008, 05:27 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If the text does not need to be editable then I would simply use a Label control:

html Code:
<asp:Label ID="labelFoo" runat="server" />

csharp Code:
labelFoo.Text = String.Format("(Dear Mr {0}<p>here i Am plaesed to )", ltxtname.Text)

Your paragraph (<p>) should be rendered fine. The {0} is a place holder, it refers to the first element in the second parameter of String.Format and, in this case, it refers to ltxtname.Text. So if you wanted to do something like you are suggesting it might look like this:

csharp Code:
labelFoo.Text = String.Format("(Dear Mr {0}<p>here i Am plaesed to..</p><p>Kind regards</p><p>{1}</p> )", ltxtname.Text, "Doug")

Which would output:

Dear Mr Foo

here I am plaesed to...

Kind regards

Doug

Will this work for you?

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================

Last edited by dparsons; December 21st, 2008 at 05:30 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab function + <textarea></textarea> Adam H-W HTML Code Clinic 0 April 24th, 2007 10:36 AM
trying to assign a parameter value to 'match=' hottub XSLT 3 April 3rd, 2006 10:18 AM
How to assign value in dropdown list ankur_bhargava2000 ASP.NET 1.0 and 1.1 Basics 3 September 25th, 2005 11:07 PM
display vbCrLf's from textarea to textarea mat41 Classic ASP Basics 8 June 10th, 2004 12:19 AM
assign a recordset to a variable biggen55 VB How-To 1 March 26th, 2004 02:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.