Override Render method in Label Control

J

Jason Dean

Hello,

I have a simple asp:label control that I want to write some complicated HTML
to. Currently I have this code and it works fine:

myLable.Text = "<p>this is my text</p>"

Bust as my HTML gets more complicated I want to be able to use the
HTMLTextWriter to write the HTML like so:

writer.Write (@"

<p>this is my text</p>
<p>this is more text</p>
<p>this is alot more text</p>

")

What is the best way to go about this?

Thx
 
B

bruce barker

you could create a new HtmlTextWriter wrapped around a stringwriter, to
build the string, or create a new control (my choice).

-- bruce (sqlwork.com)

| Hello,
|
| I have a simple asp:label control that I want to write some complicated
HTML
| to. Currently I have this code and it works fine:
|
| myLable.Text = "<p>this is my text</p>"
|
| Bust as my HTML gets more complicated I want to be able to use the
| HTMLTextWriter to write the HTML like so:
|
| writer.Write (@"
|
| <p>this is my text</p>
| <p>this is more text</p>
| <p>this is alot more text</p>
|
| ")
|
| What is the best way to go about this?
|
| Thx
|
|
 
J

Jason Dean

How exactly does this work? I've tried writing to a variable (ideal choice)
and can't seem to figure it out. Do you have any examples or links you
could send me?

Thanks soooooo much!

-Jason
 
B

bruce barker

the control is simple, define it in the page behind, change the tag on the
aspx page, and you're done.

public class mylabel : Label
{
protected override Render(HtmlTextWriter output)
{
output.Write("whatever I want");
}
}


-- bruce (sqlwork.com)

| How exactly does this work? I've tried writing to a variable (ideal
choice)
| and can't seem to figure it out. Do you have any examples or links you
| could send me?
|
| Thanks soooooo much!
|
| -Jason
|
| | > you could create a new HtmlTextWriter wrapped around a stringwriter, to
| > build the string, or create a new control (my choice).
| >
| > -- bruce (sqlwork.com)
| >
| > | > | Hello,
| > |
| > | I have a simple asp:label control that I want to write some
complicated
| > HTML
| > | to. Currently I have this code and it works fine:
| > |
| > | myLable.Text = "<p>this is my text</p>"
| > |
| > | Bust as my HTML gets more complicated I want to be able to use the
| > | HTMLTextWriter to write the HTML like so:
| > |
| > | writer.Write (@"
| > |
| > | <p>this is my text</p>
| > | <p>this is more text</p>
| > | <p>this is alot more text</p>
| > |
| > | ")
| > |
| > | What is the best way to go about this?
| > |
| > | Thx
| > |
| > |
| >
| >
|
|
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top