Showing posts with label custom. Show all posts
Showing posts with label custom. Show all posts

Monday, March 26, 2012

HTML encoding label component - best practice?

Just written a quick little custom control, decended from Label, with an
extract bool property NeedHtmlEncode, that will automatically HTML encode
the Text property.

In the Render method, I can't just use HttpUtility.HtmlEncode(Text) because
it won't deal with fonts, bold etc etc. So I wrote the following bodge to
set the Text property with the encoded value, render as normal, then reset
Text back to it's original value.

I'm sure there is a better way, can anyone help?

Thanks,

John

protected override void Render(HtmlTextWriter output)
{
if (needHtmlEncode)
{
string s = Text;
try
{
Text = System.Web.HttpUtility.HtmlEncode(Text);
base.Render(output);
}
finally
{
Text = s;
}
}
else
// normal, without encoding
base.Render(output);
}

Saturday, March 24, 2012

HTML Decoding

Hi Gang,
I have text that I am putting into a label that has been custom formatted by
a text editor and looks like this:
Some outside text <crl>Some inside text</clr> Some outside text
How can I map this to an item in a CSS file so that I can use it to format
the 'Some inside text' portion of the text?
Thanks.
SteveWell I dont think you can map it to CSS without changing it to something CSS
can identify against. So, before you add the text to the label do a string
replace on the crl so it becomes a DIV and manipulate the DIV as you would
any div from CSS. Of course you'll need to close the DIV correctly also.
So:
Some outside text <crl>Some inside text</clr> Some outside text
becomes
Some outside text <div class="crl">Some inside text</div> Some outside text
Regards
John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"Uriah Piddle" <stephenprescott@.msn.com> wrote in message
news:u10TlMoMHHA.5012@.TK2MSFTNGP02.phx.gbl...
> Hi Gang,
> I have text that I am putting into a label that has been custom formatted
> by a text editor and looks like this:
> Some outside text <crl>Some inside text</clr> Some outside text
> How can I map this to an item in a CSS file so that I can use it to format
> the 'Some inside text' portion of the text?
> Thanks.
> Steve
>
Thanks John.
"John Timney (MVP)" <x_john@.timney.eclipse.co.uk> wrote in message
news:hsCdndgnoeim0jzYnZ2dnUVZ8tqqnZ2d@.ec
lipse.net.uk...
> Well I dont think you can map it to CSS without changing it to something
> CSS can identify against. So, before you add the text to the label do a
> string replace on the crl so it becomes a DIV and manipulate the DIV as
> you would any div from CSS. Of course you'll need to close the DIV
> correctly also.
> So:
> Some outside text <crl>Some inside text</clr> Some outside text
> becomes
> Some outside text <div class="crl">Some inside text</div> Some outside
> text
> --
> Regards
> John Timney (MVP)
> VISIT MY WEBSITE:
> http://www.johntimney.com
> http://www.johntimney.com/blog
>
> "Uriah Piddle" <stephenprescott@.msn.com> wrote in message
> news:u10TlMoMHHA.5012@.TK2MSFTNGP02.phx.gbl...
>

HTML Decoding

Hi Gang,

I have text that I am putting into a label that has been custom formatted by
a text editor and looks like this:

Some outside text <crl>Some inside text</clr Some outside text

How can I map this to an item in a CSS file so that I can use it to format
the 'Some inside text' portion of the text?

Thanks.

SteveWell I dont think you can map it to CSS without changing it to something CSS
can identify against. So, before you add the text to the label do a string
replace on the crl so it becomes a DIV and manipulate the DIV as you would
any div from CSS. Of course you'll need to close the DIV correctly also.

So:
Some outside text <crl>Some inside text</clr Some outside text
becomes
Some outside text <div class="crl">Some inside text</div Some outside text

--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
"Uriah Piddle" <stephenprescott@.msn.comwrote in message
news:u10TlMoMHHA.5012@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hi Gang,
>
I have text that I am putting into a label that has been custom formatted
by a text editor and looks like this:
>
Some outside text <crl>Some inside text</clr Some outside text
>
How can I map this to an item in a CSS file so that I can use it to format
the 'Some inside text' portion of the text?
>
Thanks.
>
Steve
>


Thanks John.

"John Timney (MVP)" <x_john@.timney.eclipse.co.ukwrote in message
news:hsCdndgnoeim0jzYnZ2dnUVZ8tqqnZ2d@.eclipse.net. uk...

Quote:

Originally Posted by

Well I dont think you can map it to CSS without changing it to something
CSS can identify against. So, before you add the text to the label do a
string replace on the crl so it becomes a DIV and manipulate the DIV as
you would any div from CSS. Of course you'll need to close the DIV
correctly also.
>
So:
Some outside text <crl>Some inside text</clr Some outside text
becomes
Some outside text <div class="crl">Some inside text</div Some outside
text
>
--
Regards
>
John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
>
>
"Uriah Piddle" <stephenprescott@.msn.comwrote in message
news:u10TlMoMHHA.5012@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>Hi Gang,
>>
>I have text that I am putting into a label that has been custom formatted
>by a text editor and looks like this:
>>
> Some outside text <crl>Some inside text</clr Some outside text
>>
>How can I map this to an item in a CSS file so that I can use it to
>format the 'Some inside text' portion of the text?
>>
>Thanks.
>>
>Steve
>>


>
>