Hi Steven,
As for the WebControl's Attributes being HtmlEncoded when rendering, it is
a internal behavior of the HtmlTextWriter as Bruce has mentioned. And yes,
the HtmlTextWriter did has a RegisterAttribute Method which is like:
static void RegisterAttribute(string name, HtmlTextWriterAttribute key,
bool fEncode)
the fEncode just used to specify whether the attribute value will be
htmlencoded. However, the problem is that this method is private so that we
can't call it outside the class itself. So currently we're limited to the
internal Attributes collection and the HtmlTextWriter's default setting.
I'll suggest you use the workaround Gregory mentioend if you do feel it
necessary to avoid the script code being encoded.
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Attributes added at runtime get HTML encoded
| thread-index: AcWItTEtpBR/JbBYTYqCoYuABCyaug==
| X-WBNR-Posting-Host: 70.26.197.142
| From: "=?Utf-8?B?U3RldmVuIEJlcmtvdml0eg==?=" <mb****@community.nospam>
| References: <60**********************************@microsoft.co m>
<#G**************@TK2MSFTNGP09.phx.gbl>
| Subject: Re: Attributes added at runtime get HTML encoded
| Date: Thu, 14 Jul 2005 13:47:04 -0700
| Lines: 42
| Message-ID: <32**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:112301
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| That definitely sounds like what I am looking for, now how do I apply
that to
| a textbox (for example)?
| --
| -Steven
|
|
| "Bruce Barker" wrote:
|
| > the HtmlWriter, has encoding conventions for each attribute (default is
| > encode). onkeydown is not included in its default set, so it defualts
to
| > encode. use the RegisterAttribute() method to setup the proper encoding
for
| > this attribute.
| >
| > -- bruce (sqlwork.com)
| >
| >
| > "Steven Berkovitz" <mb****@community.nospam> wrote in message
| > news:60**********************************@microsof t.com...
| > > Hi there,
| > >
| > > I am having a problem where if i add an attribute to a control at
runtime
| > > the rendered attribute is HTML encoded.
| > >
| > > For example, on a textbox:
| > >
| > > textBox.Attributes["onKeyDown"] = "if(x && y) alert('hello');";
| > >
| > > Gets rendered as:
| > >
| > > onKeyDown="if(x && y) alert('hello');"
| > >
| > > Does anyone know how to avoid this behavior?
| > >
| > > Thanks,
| > >
| > >
| > >
| > > --
| > > -Steven
| >
| >
| >
|