468,505 Members | 1,731 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

asp.net and XHTML

How can I stop asp.net from rendering XHTML istead of HTML?
My javascripts are rendering wrong because of that. It is rendering & to
clients instead of &.
Any help?
Thanks,
Alejandro.
Nov 19 '05 #1
12 2162
How do you render your scripts ?

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:uq**************@TK2MSFTNGP10.phx.gbl...
How can I stop asp.net from rendering XHTML istead of HTML?
My javascripts are rendering wrong because of that. It is rendering &amp; to clients instead of &.
Any help?
Thanks,
Alejandro.

Nov 19 '05 #2
like this:

this.txtUserName.Attributes.Add("onkeydown","if((e vent.which && event.which
== 13)||(event.keyCode && event.keyCode ==
13)){document.Form1.cmdLogin.click();return false;}else return true;");

that code rendered javascript to the client OK. Now that I upgraded to
ASP.NET 2 Beta 2 it is rendering &amp;&amp; instead of &&, so clients are
getting this instead:

if((event.which &amp;&amp; event.which == 13)||(event.keyCode &amp;&amp;
event.keyCode == 13)){document.Form1.cmdLogin.click();return false;}else
return true;

"Patrice" <no****@nowhere.com> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
How do you render your scripts ?

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:uq**************@TK2MSFTNGP10.phx.gbl...
How can I stop asp.net from rendering XHTML istead of HTML?
My javascripts are rendering wrong because of that. It is rendering &amp;

to
clients instead of &.
Any help?
Thanks,
Alejandro.


Nov 19 '05 #3
Alex D. wrote:
How can I stop asp.net from rendering XHTML istead of HTML?
My javascripts are rendering wrong because of that. It is rendering
&amp; to clients instead of &.
Any help?


ASP.NET 1.x does not render XHTML. &amp; is correct HTML.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #4
maybe is correct HTML but definitly is not correct javascript.
I am using ASP.NET 2 Beta 2. My code worked OK when using ASP.NET 1.x

"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn****************@msnews.microsoft.com...
Alex D. wrote:
How can I stop asp.net from rendering XHTML istead of HTML?
My javascripts are rendering wrong because of that. It is rendering
&amp; to clients instead of &.
Any help?


ASP.NET 1.x does not render XHTML. &amp; is correct HTML.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 19 '05 #5
As noted by Joerg, this is HTML not XHTML...

If it really causes a problem you could register the client script using the
"ClientScript" member of the page class and just make the call using
Attributes.Add. Here you render the script as an HTML attribute causing the
string to be HTML encoded (likely ASP.NET doesn't check anyhting, this is an
HTML attribute then it encodes it)...

Let us know about your findings (especially if using HTML encoded scripts
causes a problem on some browsers)...

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OJ**************@TK2MSFTNGP09.phx.gbl...
like this:

this.txtUserName.Attributes.Add("onkeydown","if((e vent.which && event.which == 13)||(event.keyCode && event.keyCode ==
13)){document.Form1.cmdLogin.click();return false;}else return true;");

that code rendered javascript to the client OK. Now that I upgraded to
ASP.NET 2 Beta 2 it is rendering &amp;&amp; instead of &&, so clients are
getting this instead:

if((event.which &amp;&amp; event.which == 13)||(event.keyCode &amp;&amp;
event.keyCode == 13)){document.Form1.cmdLogin.click();return false;}else
return true;

"Patrice" <no****@nowhere.com> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
How do you render your scripts ?

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:uq**************@TK2MSFTNGP10.phx.gbl...
How can I stop asp.net from rendering XHTML istead of HTML?
My javascripts are rendering wrong because of that. It is rendering
&amp; to
clients instead of &.
Any help?
Thanks,
Alejandro.



Nov 19 '05 #6
Alex D. wrote:
maybe is correct HTML but definitly is not correct javascript.
I am using ASP.NET 2 Beta 2. My code worked OK when using ASP.NET 1.x


Note that the HTML output of ASP.NET 1.x was, um, kinda crappy. So
saying "it worked" doesn't imply it was correct :-/

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #7
my friend, I get the same problem even if I insert the code here:

<FORM id=Form1 method=post runat="server" onload=
"if((event.which && event.which== 13)||(event.keyCode && event.keyCode ==
13)){document.Form1.cmdLogin.click();return false;}else return true;");>

but if I insert the code BEFORE the FORM tag , let say, inside the BODY,
then it render & instead of &amp; which is OK. SO it is an XHTML related
problem

If you are interested you can read this, I tried the suggested solution to
disable XHTML but it didn't work.

ASP.NET and XHTML Compliance
ASP.NET allows you to create Web pages that are compliant with XHTML 1.1
standards. XHTML is a W3C standard that defines HTML as an XML document.
Creating Web pages that are conformant with XHTML standards guarantees that
the elements in the pages are well formed. Because many browsers are moving
toward supporting XHTML, creating pages that conform to XHTML standards
helps ensure that your pages will be compatible with browsers in the future.
XHTML is also extensible, allowing the definition of new elements. Finally,
an XHTML page is much easier to read programmatically for situations in
which the Web page is processed by a computer rather than read by users, and
the document can be manipulated using transformations. For more information
about the XHTML standard, see the W3C site at www.w3.org/TR/xhtml1.

Compliance Features
XHTML defines elements and attributes more strictly than HTML. By default,
all markup produced by ASP.NET and Web server controls included with ASP.NET
now conforms to this standard.

Some of the XHTML rules that differ from HTML include the following:

a.. All elements either include an explicit closing tag or are
self-closing (with />).

b.. Tag and attribute names are rendered in lowercase, and attribute
values are included in double quotation marks. For example, if you use a
System.Web.UI.WebControls.GridView control on your page, when the page is
rendered, the System.Web.UI.WebControls.GridView control emits HTML that is
XHTML compliant. All generated elements use explicit opening and closing
tags (or self-closing tags), and attribute values are included in double
quotation marks.

c.. Formatting information is rendered using only cascading style sheet
styler. To support this standard, ASP.NET controls do not render <font> tags
or attributes such as bgcolor.

d.. Controls do not render custom attributes (expando attributes) that are
not defined in the XHTML standards.

e.. In ASP.NET, if controls generate IDs, as occurs in the Repeater,
GridView, and other controls, the format of the IDs is XHTML 1.1 compliant.

f.. ASP.NET dynamically adds an action attribute to the form tag. Because
XHTML 1.1 prohibits it, form tags do not include a name attribute.

g.. Because XHTML requires all elements to be enclosed in a container
element, ASP.NET controls such as input elements are rendered in div
elements. This includes the HTML markup rendered for controls such as the
TextBox, CheckBox, and RadioButton controls. It also includes hidden fields,
such as the element used to store view-state data.

h.. ASP.NET codes characters such as & (for example, as &amp;). This
includes URLs that are generated to reference JavaScript script and the
contents of encoded values such as view state.

i.. Any script tags rendered into the page include an appropriate type
attribute. (This pertains to scripts that are created by the page or
controls or by the RegisterHiddenField, RegisterStartupScript, and
RegisterClientScriptBlock methods; script blocks that you create are not
automatically amended with a type attribute.) In ASP.NET any script tags
rendered by the page use the appropriate type attribute
(type="type/javascript") and do not include a language attribute. ASP.NET
renders script tags when the page includes certain controls (such as the
System.Web.UI.WebControls.HyperLink , System.Web.UI.WebControls.LinkButton ,
and System.Web.UI.WebControls.Calendar controls) that require client script
to perform a postback. Script is also rendered for controls that rely on
client-side functionality, such as the System.Web.UI.WebControls.TreeView
and validator controls.

j.. IF ASP.NET renders script blocks, the contents of the script blocks is
rendered in CDATA elements (inside <![CDATA[ and ]]> tags) to prevent
special characters such as & and < from being interpreted as XML.

Controlling XHTML Rendering of ASP.NET Page and Controls
Under some circumstances, you might not want ASP.NET controls to render
XHTML 1.1 markup. For example, XHTML 1.1 standards prohibit the use of a
name attribute in an HTML form tag, so ASP.NET does not render that
attribute. However, in your application, you might have existing pages with
client script that relies on the form tag's name attribute.

You can configure ASP.NET so that it does not render XHTML 1.1 markup to
allow pages created in earlier versions of ASP.NET to work as designed. For
more information, see How to: Configure ASP.NET for Non-XHTML Rendering.

"Patrice" <no****@nowhere.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
As noted by Joerg, this is HTML not XHTML...

If it really causes a problem you could register the client script using
the
"ClientScript" member of the page class and just make the call using
Attributes.Add. Here you render the script as an HTML attribute causing
the
string to be HTML encoded (likely ASP.NET doesn't check anyhting, this is
an
HTML attribute then it encodes it)...

Let us know about your findings (especially if using HTML encoded scripts
causes a problem on some browsers)...

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OJ**************@TK2MSFTNGP09.phx.gbl...
like this:

this.txtUserName.Attributes.Add("onkeydown","if((e vent.which &&

event.which
== 13)||(event.keyCode && event.keyCode ==
13)){document.Form1.cmdLogin.click();return false;}else return true;");

that code rendered javascript to the client OK. Now that I upgraded to
ASP.NET 2 Beta 2 it is rendering &amp;&amp; instead of &&, so clients are
getting this instead:

if((event.which &amp;&amp; event.which == 13)||(event.keyCode &amp;&amp;
event.keyCode == 13)){document.Form1.cmdLogin.click();return false;}else
return true;

"Patrice" <no****@nowhere.com> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
> How do you render your scripts ?
>
> Patrice
>
> --
>
> "Alex D." <al********@hotmail.com> a écrit dans le message de
> news:uq**************@TK2MSFTNGP10.phx.gbl...
>> How can I stop asp.net from rendering XHTML istead of HTML?
>> My javascripts are rendering wrong because of that. It is rendering &amp; > to
>> clients instead of &.
>> Any help?
>> Thanks,
>> Alejandro.
>>
>>
>
>



Nov 19 '05 #8
whole article: http://msdn2.microsoft.com/library/e...us,vs.80).aspx
"Patrice" <no****@nowhere.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
As noted by Joerg, this is HTML not XHTML...

If it really causes a problem you could register the client script using
the
"ClientScript" member of the page class and just make the call using
Attributes.Add. Here you render the script as an HTML attribute causing
the
string to be HTML encoded (likely ASP.NET doesn't check anyhting, this is
an
HTML attribute then it encodes it)...

Let us know about your findings (especially if using HTML encoded scripts
causes a problem on some browsers)...

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OJ**************@TK2MSFTNGP09.phx.gbl...
like this:

this.txtUserName.Attributes.Add("onkeydown","if((e vent.which &&

event.which
== 13)||(event.keyCode && event.keyCode ==
13)){document.Form1.cmdLogin.click();return false;}else return true;");

that code rendered javascript to the client OK. Now that I upgraded to
ASP.NET 2 Beta 2 it is rendering &amp;&amp; instead of &&, so clients are
getting this instead:

if((event.which &amp;&amp; event.which == 13)||(event.keyCode &amp;&amp;
event.keyCode == 13)){document.Form1.cmdLogin.click();return false;}else
return true;

"Patrice" <no****@nowhere.com> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
> How do you render your scripts ?
>
> Patrice
>
> --
>
> "Alex D." <al********@hotmail.com> a écrit dans le message de
> news:uq**************@TK2MSFTNGP10.phx.gbl...
>> How can I stop asp.net from rendering XHTML istead of HTML?
>> My javascripts are rendering wrong because of that. It is rendering &amp; > to
>> clients instead of &.
>> Any help?
>> Thanks,
>> Alejandro.
>>
>>
>
>



Nov 19 '05 #9
What I meant was to use Me.ClientScript.RegisterClientScriptBlock to render
the script and then use attributes.add just to call it... AFAIK scripts
registered his way are not encoded (the trick is that this function knows
this a script while attributes.add doesn't know what you are doing).

What browser are you using ? Here HTML encoded JavaScript code seems to work
fine...

Hope I'm clearer...

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OO**************@TK2MSFTNGP10.phx.gbl...
my friend, I get the same problem even if I insert the code here:

<FORM id=Form1 method=post runat="server" onload=
"if((event.which && event.which== 13)||(event.keyCode && event.keyCode ==
13)){document.Form1.cmdLogin.click();return false;}else return true;");>

but if I insert the code BEFORE the FORM tag , let say, inside the BODY,
then it render & instead of &amp; which is OK. SO it is an XHTML related
problem

If you are interested you can read this, I tried the suggested solution to
disable XHTML but it didn't work.

ASP.NET and XHTML Compliance
ASP.NET allows you to create Web pages that are compliant with XHTML 1.1
standards. XHTML is a W3C standard that defines HTML as an XML document.
Creating Web pages that are conformant with XHTML standards guarantees that the elements in the pages are well formed. Because many browsers are moving toward supporting XHTML, creating pages that conform to XHTML standards
helps ensure that your pages will be compatible with browsers in the future. XHTML is also extensible, allowing the definition of new elements. Finally, an XHTML page is much easier to read programmatically for situations in
which the Web page is processed by a computer rather than read by users, and the document can be manipulated using transformations. For more information about the XHTML standard, see the W3C site at www.w3.org/TR/xhtml1.

Compliance Features
XHTML defines elements and attributes more strictly than HTML. By default,
all markup produced by ASP.NET and Web server controls included with ASP.NET now conforms to this standard.

Some of the XHTML rules that differ from HTML include the following:

a.. All elements either include an explicit closing tag or are
self-closing (with />).

b.. Tag and attribute names are rendered in lowercase, and attribute
values are included in double quotation marks. For example, if you use a
System.Web.UI.WebControls.GridView control on your page, when the page is
rendered, the System.Web.UI.WebControls.GridView control emits HTML that is XHTML compliant. All generated elements use explicit opening and closing
tags (or self-closing tags), and attribute values are included in double
quotation marks.

c.. Formatting information is rendered using only cascading style sheet
styler. To support this standard, ASP.NET controls do not render <font> tags or attributes such as bgcolor.

d.. Controls do not render custom attributes (expando attributes) that are not defined in the XHTML standards.

e.. In ASP.NET, if controls generate IDs, as occurs in the Repeater,
GridView, and other controls, the format of the IDs is XHTML 1.1 compliant.
f.. ASP.NET dynamically adds an action attribute to the form tag. Because XHTML 1.1 prohibits it, form tags do not include a name attribute.

g.. Because XHTML requires all elements to be enclosed in a container
element, ASP.NET controls such as input elements are rendered in div
elements. This includes the HTML markup rendered for controls such as the
TextBox, CheckBox, and RadioButton controls. It also includes hidden fields, such as the element used to store view-state data.

h.. ASP.NET codes characters such as & (for example, as &amp;). This
includes URLs that are generated to reference JavaScript script and the
contents of encoded values such as view state.

i.. Any script tags rendered into the page include an appropriate type
attribute. (This pertains to scripts that are created by the page or
controls or by the RegisterHiddenField, RegisterStartupScript, and
RegisterClientScriptBlock methods; script blocks that you create are not
automatically amended with a type attribute.) In ASP.NET any script tags
rendered by the page use the appropriate type attribute
(type="type/javascript") and do not include a language attribute. ASP.NET
renders script tags when the page includes certain controls (such as the
System.Web.UI.WebControls.HyperLink , System.Web.UI.WebControls.LinkButton , and System.Web.UI.WebControls.Calendar controls) that require client script to perform a postback. Script is also rendered for controls that rely on
client-side functionality, such as the System.Web.UI.WebControls.TreeView
and validator controls.

j.. IF ASP.NET renders script blocks, the contents of the script blocks is rendered in CDATA elements (inside <![CDATA[ and ]]> tags) to prevent
special characters such as & and < from being interpreted as XML.

Controlling XHTML Rendering of ASP.NET Page and Controls
Under some circumstances, you might not want ASP.NET controls to render
XHTML 1.1 markup. For example, XHTML 1.1 standards prohibit the use of a
name attribute in an HTML form tag, so ASP.NET does not render that
attribute. However, in your application, you might have existing pages with client script that relies on the form tag's name attribute.

You can configure ASP.NET so that it does not render XHTML 1.1 markup to
allow pages created in earlier versions of ASP.NET to work as designed. For more information, see How to: Configure ASP.NET for Non-XHTML Rendering.

"Patrice" <no****@nowhere.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
As noted by Joerg, this is HTML not XHTML...

If it really causes a problem you could register the client script using
the
"ClientScript" member of the page class and just make the call using
Attributes.Add. Here you render the script as an HTML attribute causing
the
string to be HTML encoded (likely ASP.NET doesn't check anyhting, this is an
HTML attribute then it encodes it)...

Let us know about your findings (especially if using HTML encoded scripts causes a problem on some browsers)...

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OJ**************@TK2MSFTNGP09.phx.gbl...
like this:

this.txtUserName.Attributes.Add("onkeydown","if((e vent.which &&

event.which
== 13)||(event.keyCode && event.keyCode ==
13)){document.Form1.cmdLogin.click();return false;}else return true;");

that code rendered javascript to the client OK. Now that I upgraded to
ASP.NET 2 Beta 2 it is rendering &amp;&amp; instead of &&, so clients are getting this instead:

if((event.which &amp;&amp; event.which == 13)||(event.keyCode &amp;&amp; event.keyCode == 13)){document.Form1.cmdLogin.click();return false;}else return true;

"Patrice" <no****@nowhere.com> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
> How do you render your scripts ?
>
> Patrice
>
> --
>
> "Alex D." <al********@hotmail.com> a écrit dans le message de
> news:uq**************@TK2MSFTNGP10.phx.gbl...
>> How can I stop asp.net from rendering XHTML istead of HTML?
>> My javascripts are rendering wrong because of that. It is rendering

&amp;
> to
>> clients instead of &.
>> Any help?
>> Thanks,
>> Alejandro.
>>
>>
>
>



Nov 19 '05 #10
HTML enconded javascript woks fine here too.... what doesn't work fine is
XHTML encoded javascript....
If I use Me.ClientScript.RegisterClientScriptBlock then I guess I need to
create a whole function() and then call the function from attributes.add...
is that right?
"Patrice" <no****@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
What I meant was to use Me.ClientScript.RegisterClientScriptBlock to
render
the script and then use attributes.add just to call it... AFAIK scripts
registered his way are not encoded (the trick is that this function knows
this a script while attributes.add doesn't know what you are doing).

What browser are you using ? Here HTML encoded JavaScript code seems to
work
fine...

Hope I'm clearer...

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OO**************@TK2MSFTNGP10.phx.gbl...
my friend, I get the same problem even if I insert the code here:

<FORM id=Form1 method=post runat="server" onload=
"if((event.which && event.which== 13)||(event.keyCode && event.keyCode ==
13)){document.Form1.cmdLogin.click();return false;}else return true;");>

but if I insert the code BEFORE the FORM tag , let say, inside the BODY,
then it render & instead of &amp; which is OK. SO it is an XHTML related
problem

If you are interested you can read this, I tried the suggested solution
to
disable XHTML but it didn't work.

ASP.NET and XHTML Compliance
ASP.NET allows you to create Web pages that are compliant with XHTML 1.1
standards. XHTML is a W3C standard that defines HTML as an XML document.
Creating Web pages that are conformant with XHTML standards guarantees

that
the elements in the pages are well formed. Because many browsers are

moving
toward supporting XHTML, creating pages that conform to XHTML standards
helps ensure that your pages will be compatible with browsers in the

future.
XHTML is also extensible, allowing the definition of new elements.

Finally,
an XHTML page is much easier to read programmatically for situations in
which the Web page is processed by a computer rather than read by users,

and
the document can be manipulated using transformations. For more

information
about the XHTML standard, see the W3C site at www.w3.org/TR/xhtml1.

Compliance Features
XHTML defines elements and attributes more strictly than HTML. By
default,
all markup produced by ASP.NET and Web server controls included with

ASP.NET
now conforms to this standard.

Some of the XHTML rules that differ from HTML include the following:

a.. All elements either include an explicit closing tag or are
self-closing (with />).

b.. Tag and attribute names are rendered in lowercase, and attribute
values are included in double quotation marks. For example, if you use a
System.Web.UI.WebControls.GridView control on your page, when the page is
rendered, the System.Web.UI.WebControls.GridView control emits HTML that

is
XHTML compliant. All generated elements use explicit opening and closing
tags (or self-closing tags), and attribute values are included in double
quotation marks.

c.. Formatting information is rendered using only cascading style sheet
styler. To support this standard, ASP.NET controls do not render <font>

tags
or attributes such as bgcolor.

d.. Controls do not render custom attributes (expando attributes) that

are
not defined in the XHTML standards.

e.. In ASP.NET, if controls generate IDs, as occurs in the Repeater,
GridView, and other controls, the format of the IDs is XHTML 1.1

compliant.

f.. ASP.NET dynamically adds an action attribute to the form tag.

Because
XHTML 1.1 prohibits it, form tags do not include a name attribute.

g.. Because XHTML requires all elements to be enclosed in a container
element, ASP.NET controls such as input elements are rendered in div
elements. This includes the HTML markup rendered for controls such as the
TextBox, CheckBox, and RadioButton controls. It also includes hidden

fields,
such as the element used to store view-state data.

h.. ASP.NET codes characters such as & (for example, as &amp;). This
includes URLs that are generated to reference JavaScript script and the
contents of encoded values such as view state.

i.. Any script tags rendered into the page include an appropriate type
attribute. (This pertains to scripts that are created by the page or
controls or by the RegisterHiddenField, RegisterStartupScript, and
RegisterClientScriptBlock methods; script blocks that you create are not
automatically amended with a type attribute.) In ASP.NET any script tags
rendered by the page use the appropriate type attribute
(type="type/javascript") and do not include a language attribute. ASP.NET
renders script tags when the page includes certain controls (such as the
System.Web.UI.WebControls.HyperLink ,
System.Web.UI.WebControls.LinkButton

,
and System.Web.UI.WebControls.Calendar controls) that require client

script
to perform a postback. Script is also rendered for controls that rely on
client-side functionality, such as the System.Web.UI.WebControls.TreeView
and validator controls.

j.. IF ASP.NET renders script blocks, the contents of the script blocks

is
rendered in CDATA elements (inside <![CDATA[ and ]]> tags) to prevent
special characters such as & and < from being interpreted as XML.

Controlling XHTML Rendering of ASP.NET Page and Controls
Under some circumstances, you might not want ASP.NET controls to render
XHTML 1.1 markup. For example, XHTML 1.1 standards prohibit the use of a
name attribute in an HTML form tag, so ASP.NET does not render that
attribute. However, in your application, you might have existing pages

with
client script that relies on the form tag's name attribute.

You can configure ASP.NET so that it does not render XHTML 1.1 markup to
allow pages created in earlier versions of ASP.NET to work as designed.

For
more information, see How to: Configure ASP.NET for Non-XHTML Rendering.

"Patrice" <no****@nowhere.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
> As noted by Joerg, this is HTML not XHTML...
>
> If it really causes a problem you could register the client script
> using
> the
> "ClientScript" member of the page class and just make the call using
> Attributes.Add. Here you render the script as an HTML attribute causing
> the
> string to be HTML encoded (likely ASP.NET doesn't check anyhting, this is > an
> HTML attribute then it encodes it)...
>
> Let us know about your findings (especially if using HTML encoded scripts > causes a problem on some browsers)...
>
> Patrice
>
> --
>
> "Alex D." <al********@hotmail.com> a écrit dans le message de
> news:OJ**************@TK2MSFTNGP09.phx.gbl...
>> like this:
>>
>> this.txtUserName.Attributes.Add("onkeydown","if((e vent.which &&
> event.which
>> == 13)||(event.keyCode && event.keyCode ==
>> 13)){document.Form1.cmdLogin.click();return false;}else return
>> true;");
>>
>> that code rendered javascript to the client OK. Now that I upgraded to
>> ASP.NET 2 Beta 2 it is rendering &amp;&amp; instead of &&, so clients are >> getting this instead:
>>
>> if((event.which &amp;&amp; event.which == 13)||(event.keyCode &amp;&amp; >> event.keyCode == 13)){document.Form1.cmdLogin.click();return false;}else >> return true;
>>
>>
>>
>>
>>
>> "Patrice" <no****@nowhere.com> wrote in message
>> news:uL**************@TK2MSFTNGP09.phx.gbl...
>> > How do you render your scripts ?
>> >
>> > Patrice
>> >
>> > --
>> >
>> > "Alex D." <al********@hotmail.com> a écrit dans le message de
>> > news:uq**************@TK2MSFTNGP10.phx.gbl...
>> >> How can I stop asp.net from rendering XHTML istead of HTML?
>> >> My javascripts are rendering wrong because of that. It is rendering
> &amp;
>> > to
>> >> clients instead of &.
>> >> Any help?
>> >> Thanks,
>> >> Alejandro.
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 19 '05 #11
Yes this is what I meant...

I don't see what difference you ake between "XHTML" and "HTML" encoded
scripts...

For example the problme seems to be related to & being &amp;

What if you try just :

TextBox1.Attributes.Add("onkeydown","alert(8 && 4);")

Even if it is rendered as :
onkeydown="alert(8 &amp;&amp; 4);" does it work as expected ?

Patrice
--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OB**************@TK2MSFTNGP10.phx.gbl...
HTML enconded javascript woks fine here too.... what doesn't work fine is
XHTML encoded javascript....
If I use Me.ClientScript.RegisterClientScriptBlock then I guess I need to
create a whole function() and then call the function from attributes.add... is that right?
"Patrice" <no****@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
What I meant was to use Me.ClientScript.RegisterClientScriptBlock to
render
the script and then use attributes.add just to call it... AFAIK scripts
registered his way are not encoded (the trick is that this function knows this a script while attributes.add doesn't know what you are doing).

What browser are you using ? Here HTML encoded JavaScript code seems to
work
fine...

Hope I'm clearer...

Patrice

--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OO**************@TK2MSFTNGP10.phx.gbl...
my friend, I get the same problem even if I insert the code here:

<FORM id=Form1 method=post runat="server" onload=
"if((event.which && event.which== 13)||(event.keyCode && event.keyCode == 13)){document.Form1.cmdLogin.click();return false;}else return true;");>
but if I insert the code BEFORE the FORM tag , let say, inside the BODY, then it render & instead of &amp; which is OK. SO it is an XHTML related problem

If you are interested you can read this, I tried the suggested solution to
disable XHTML but it didn't work.

ASP.NET and XHTML Compliance
ASP.NET allows you to create Web pages that are compliant with XHTML 1.1 standards. XHTML is a W3C standard that defines HTML as an XML document. Creating Web pages that are conformant with XHTML standards guarantees

that
the elements in the pages are well formed. Because many browsers are

moving
toward supporting XHTML, creating pages that conform to XHTML standards
helps ensure that your pages will be compatible with browsers in the

future.
XHTML is also extensible, allowing the definition of new elements.

Finally,
an XHTML page is much easier to read programmatically for situations in
which the Web page is processed by a computer rather than read by users,
and
the document can be manipulated using transformations. For more

information
about the XHTML standard, see the W3C site at www.w3.org/TR/xhtml1.

Compliance Features
XHTML defines elements and attributes more strictly than HTML. By
default,
all markup produced by ASP.NET and Web server controls included with

ASP.NET
now conforms to this standard.

Some of the XHTML rules that differ from HTML include the following:

a.. All elements either include an explicit closing tag or are
self-closing (with />).

b.. Tag and attribute names are rendered in lowercase, and attribute
values are included in double quotation marks. For example, if you use
a System.Web.UI.WebControls.GridView control on your page, when the page is rendered, the System.Web.UI.WebControls.GridView control emits HTML that is
XHTML compliant. All generated elements use explicit opening and
closing tags (or self-closing tags), and attribute values are included in double quotation marks.

c.. Formatting information is rendered using only cascading style sheet styler. To support this standard, ASP.NET controls do not render <font>

tags
or attributes such as bgcolor.

d.. Controls do not render custom attributes (expando attributes) that are
not defined in the XHTML standards.

e.. In ASP.NET, if controls generate IDs, as occurs in the Repeater,
GridView, and other controls, the format of the IDs is XHTML 1.1

compliant.

f.. ASP.NET dynamically adds an action attribute to the form tag.

Because
XHTML 1.1 prohibits it, form tags do not include a name attribute.

g.. Because XHTML requires all elements to be enclosed in a container
element, ASP.NET controls such as input elements are rendered in div
elements. This includes the HTML markup rendered for controls such as
the TextBox, CheckBox, and RadioButton controls. It also includes hidden

fields,
such as the element used to store view-state data.

h.. ASP.NET codes characters such as & (for example, as &amp;). This
includes URLs that are generated to reference JavaScript script and the
contents of encoded values such as view state.

i.. Any script tags rendered into the page include an appropriate type attribute. (This pertains to scripts that are created by the page or
controls or by the RegisterHiddenField, RegisterStartupScript, and
RegisterClientScriptBlock methods; script blocks that you create are not automatically amended with a type attribute.) In ASP.NET any script tags rendered by the page use the appropriate type attribute
(type="type/javascript") and do not include a language attribute. ASP.NET renders script tags when the page includes certain controls (such as the System.Web.UI.WebControls.HyperLink ,
System.Web.UI.WebControls.LinkButton

,
and System.Web.UI.WebControls.Calendar controls) that require client

script
to perform a postback. Script is also rendered for controls that rely on client-side functionality, such as the System.Web.UI.WebControls.TreeView and validator controls.

j.. IF ASP.NET renders script blocks, the contents of the script blocks is
rendered in CDATA elements (inside <![CDATA[ and ]]> tags) to prevent
special characters such as & and < from being interpreted as XML.

Controlling XHTML Rendering of ASP.NET Page and Controls
Under some circumstances, you might not want ASP.NET controls to render
XHTML 1.1 markup. For example, XHTML 1.1 standards prohibit the use of
a name attribute in an HTML form tag, so ASP.NET does not render that
attribute. However, in your application, you might have existing pages

with
client script that relies on the form tag's name attribute.

You can configure ASP.NET so that it does not render XHTML 1.1 markup to allow pages created in earlier versions of ASP.NET to work as designed.

For
more information, see How to: Configure ASP.NET for Non-XHTML Rendering.
"Patrice" <no****@nowhere.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
> As noted by Joerg, this is HTML not XHTML...
>
> If it really causes a problem you could register the client script
> using
> the
> "ClientScript" member of the page class and just make the call using
> Attributes.Add. Here you render the script as an HTML attribute causing > the
> string to be HTML encoded (likely ASP.NET doesn't check anyhting, this is
> an
> HTML attribute then it encodes it)...
>
> Let us know about your findings (especially if using HTML encoded

scripts
> causes a problem on some browsers)...
>
> Patrice
>
> --
>
> "Alex D." <al********@hotmail.com> a écrit dans le message de
> news:OJ**************@TK2MSFTNGP09.phx.gbl...
>> like this:
>>
>> this.txtUserName.Attributes.Add("onkeydown","if((e vent.which &&
> event.which
>> == 13)||(event.keyCode && event.keyCode ==
>> 13)){document.Form1.cmdLogin.click();return false;}else return
>> true;");
>>
>> that code rendered javascript to the client OK. Now that I upgraded
to >> ASP.NET 2 Beta 2 it is rendering &amp;&amp; instead of &&, so clients are
>> getting this instead:
>>
>> if((event.which &amp;&amp; event.which == 13)||(event.keyCode

&amp;&amp;
>> event.keyCode == 13)){document.Form1.cmdLogin.click();return

false;}else
>> return true;
>>
>>
>>
>>
>>
>> "Patrice" <no****@nowhere.com> wrote in message
>> news:uL**************@TK2MSFTNGP09.phx.gbl...
>> > How do you render your scripts ?
>> >
>> > Patrice
>> >
>> > --
>> >
>> > "Alex D." <al********@hotmail.com> a écrit dans le message de
>> > news:uq**************@TK2MSFTNGP10.phx.gbl...
>> >> How can I stop asp.net from rendering XHTML istead of HTML?
>> >> My javascripts are rendering wrong because of that. It is

rendering > &amp;
>> > to
>> >> clients instead of &.
>> >> Any help?
>> >> Thanks,
>> >> Alejandro.
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 19 '05 #12
this is the difference:
Some of the XHTML rules that differ from HTML include the following:

a.. All elements either include an explicit closing tag or are
self-closing (with />).

b.. Tag and attribute names are rendered in lowercase, and attribute
values are included in double quotation marks. For example, if you use a
System.Web.UI.WebControls.GridView control on your page, when the page is
rendered, the System.Web.UI.WebControls.GridView control emits HTML that is
XHTML compliant. All generated elements use explicit opening and closing
tags (or self-closing tags), and attribute values are included in double
quotation marks.

c.. Formatting information is rendered using only cascading style sheet
styler. To support this standard, ASP.NET controls do not render <font> tags
or attributes such as bgcolor.

d.. Controls do not render custom attributes (expando attributes) that are
not defined in the XHTML standards.

e.. In ASP.NET, if controls generate IDs, as occurs in the Repeater,
GridView, and other controls, the format of the IDs is XHTML 1.1 compliant.

f.. ASP.NET dynamically adds an action attribute to the form tag. Because
XHTML 1.1 prohibits it, form tags do not include a name attribute.

g.. Because XHTML requires all elements to be enclosed in a container
element, ASP.NET controls such as input elements are rendered in div
elements. This includes the HTML markup rendered for controls such as the
TextBox, CheckBox, and RadioButton controls. It also includes hidden fields,
such as the element used to store view-state data.

h.. ASP.NET codes characters such as & (for example, as &amp;). This
includes URLs that are generated to reference JavaScript script and the
contents of encoded values such as view state.

i.. Any script tags rendered into the page include an appropriate type
attribute. (This pertains to scripts that are created by the page or
controls or by the RegisterHiddenField, RegisterStartupScript, and
RegisterClientScriptBlock methods; script blocks that you create are not
automatically amended with a type attribute.) In ASP.NET any script tags
rendered by the page use the appropriate type attribute
(type="type/javascript") and do not include a language attribute. ASP.NET
renders script tags when the page includes certain controls (such as the
System.Web.UI.WebControls.HyperLink , System.Web.UI.WebControls.LinkButton ,
and System.Web.UI.WebControls.Calendar controls) that require client script
to perform a postback. Script is also rendered for controls that rely on
client-side functionality, such as the System.Web.UI.WebControls.TreeView
and validator controls.

j.. IF ASP.NET renders script blocks, the contents of the script blocks is
rendered in CDATA elements (inside <![CDATA[ and ]]> tags) to prevent
special characters such as & and < from being interpreted as XML.

"Patrice" <no****@nowhere.com> wrote in message
news:u9****************@tk2msftngp13.phx.gbl...
Yes this is what I meant...

I don't see what difference you ake between "XHTML" and "HTML" encoded
scripts...

For example the problme seems to be related to & being &amp;

What if you try just :

TextBox1.Attributes.Add("onkeydown","alert(8 && 4);")

Even if it is rendered as :
onkeydown="alert(8 &amp;&amp; 4);" does it work as expected ?

Patrice
--

"Alex D." <al********@hotmail.com> a écrit dans le message de
news:OB**************@TK2MSFTNGP10.phx.gbl...
HTML enconded javascript woks fine here too.... what doesn't work fine is
XHTML encoded javascript....
If I use Me.ClientScript.RegisterClientScriptBlock then I guess I need to
create a whole function() and then call the function from

attributes.add...
is that right?
"Patrice" <no****@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> What I meant was to use Me.ClientScript.RegisterClientScriptBlock to
> render
> the script and then use attributes.add just to call it... AFAIK scripts
> registered his way are not encoded (the trick is that this function knows > this a script while attributes.add doesn't know what you are doing).
>
> What browser are you using ? Here HTML encoded JavaScript code seems to
> work
> fine...
>
> Hope I'm clearer...
>
> Patrice
>
> --
>
> "Alex D." <al********@hotmail.com> a écrit dans le message de
> news:OO**************@TK2MSFTNGP10.phx.gbl...
>> my friend, I get the same problem even if I insert the code here:
>>
>> <FORM id=Form1 method=post runat="server" onload=
>> "if((event.which && event.which== 13)||(event.keyCode && event.keyCode == >> 13)){document.Form1.cmdLogin.click();return false;}else return true;");> >>
>> but if I insert the code BEFORE the FORM tag , let say, inside the BODY, >> then it render & instead of &amp; which is OK. SO it is an XHTML related >> problem
>>
>> If you are interested you can read this, I tried the suggested
>> solution >> to
>> disable XHTML but it didn't work.
>>
>> ASP.NET and XHTML Compliance
>> ASP.NET allows you to create Web pages that are compliant with XHTML 1.1 >> standards. XHTML is a W3C standard that defines HTML as an XML document. >> Creating Web pages that are conformant with XHTML standards guarantees
> that
>> the elements in the pages are well formed. Because many browsers are
> moving
>> toward supporting XHTML, creating pages that conform to XHTML
>> standards
>> helps ensure that your pages will be compatible with browsers in the
> future.
>> XHTML is also extensible, allowing the definition of new elements.
> Finally,
>> an XHTML page is much easier to read programmatically for situations
>> in
>> which the Web page is processed by a computer rather than read by users, > and
>> the document can be manipulated using transformations. For more
> information
>> about the XHTML standard, see the W3C site at www.w3.org/TR/xhtml1.
>>
>> Compliance Features
>> XHTML defines elements and attributes more strictly than HTML. By
>> default,
>> all markup produced by ASP.NET and Web server controls included with
> ASP.NET
>> now conforms to this standard.
>>
>> Some of the XHTML rules that differ from HTML include the following:
>>
>> a.. All elements either include an explicit closing tag or are
>> self-closing (with />).
>>
>> b.. Tag and attribute names are rendered in lowercase, and attribute
>> values are included in double quotation marks. For example, if you use a >> System.Web.UI.WebControls.GridView control on your page, when the page is >> rendered, the System.Web.UI.WebControls.GridView control emits HTML that > is
>> XHTML compliant. All generated elements use explicit opening and closing >> tags (or self-closing tags), and attribute values are included in double >> quotation marks.
>>
>> c.. Formatting information is rendered using only cascading style sheet >> styler. To support this standard, ASP.NET controls do not render
>> <font>
> tags
>> or attributes such as bgcolor.
>>
>> d.. Controls do not render custom attributes (expando attributes) that > are
>> not defined in the XHTML standards.
>>
>> e.. In ASP.NET, if controls generate IDs, as occurs in the Repeater,
>> GridView, and other controls, the format of the IDs is XHTML 1.1
> compliant.
>>
>> f.. ASP.NET dynamically adds an action attribute to the form tag.
> Because
>> XHTML 1.1 prohibits it, form tags do not include a name attribute.
>>
>> g.. Because XHTML requires all elements to be enclosed in a
>> container
>> element, ASP.NET controls such as input elements are rendered in div
>> elements. This includes the HTML markup rendered for controls such as the >> TextBox, CheckBox, and RadioButton controls. It also includes hidden
> fields,
>> such as the element used to store view-state data.
>>
>> h.. ASP.NET codes characters such as & (for example, as &amp;). This
>> includes URLs that are generated to reference JavaScript script and
>> the
>> contents of encoded values such as view state.
>>
>> i.. Any script tags rendered into the page include an appropriate type >> attribute. (This pertains to scripts that are created by the page or
>> controls or by the RegisterHiddenField, RegisterStartupScript, and
>> RegisterClientScriptBlock methods; script blocks that you create are not >> automatically amended with a type attribute.) In ASP.NET any script tags >> rendered by the page use the appropriate type attribute
>> (type="type/javascript") and do not include a language attribute. ASP.NET >> renders script tags when the page includes certain controls (such as the >> System.Web.UI.WebControls.HyperLink ,
>> System.Web.UI.WebControls.LinkButton
> ,
>> and System.Web.UI.WebControls.Calendar controls) that require client
> script
>> to perform a postback. Script is also rendered for controls that rely on >> client-side functionality, such as the System.Web.UI.WebControls.TreeView >> and validator controls.
>>
>> j.. IF ASP.NET renders script blocks, the contents of the script blocks > is
>> rendered in CDATA elements (inside <![CDATA[ and ]]> tags) to prevent
>> special characters such as & and < from being interpreted as XML.
>>
>> Controlling XHTML Rendering of ASP.NET Page and Controls
>> Under some circumstances, you might not want ASP.NET controls to
>> render
>> XHTML 1.1 markup. For example, XHTML 1.1 standards prohibit the use of a >> name attribute in an HTML form tag, so ASP.NET does not render that
>> attribute. However, in your application, you might have existing pages
> with
>> client script that relies on the form tag's name attribute.
>>
>> You can configure ASP.NET so that it does not render XHTML 1.1 markup to >> allow pages created in earlier versions of ASP.NET to work as
>> designed.
> For
>> more information, see How to: Configure ASP.NET for Non-XHTML Rendering. >>
>>
>>
>> "Patrice" <no****@nowhere.com> wrote in message
>> news:e5**************@TK2MSFTNGP14.phx.gbl...
>> > As noted by Joerg, this is HTML not XHTML...
>> >
>> > If it really causes a problem you could register the client script
>> > using
>> > the
>> > "ClientScript" member of the page class and just make the call using
>> > Attributes.Add. Here you render the script as an HTML attribute causing >> > the
>> > string to be HTML encoded (likely ASP.NET doesn't check anyhting, this > is
>> > an
>> > HTML attribute then it encodes it)...
>> >
>> > Let us know about your findings (especially if using HTML encoded
> scripts
>> > causes a problem on some browsers)...
>> >
>> > Patrice
>> >
>> > --
>> >
>> > "Alex D." <al********@hotmail.com> a écrit dans le message de
>> > news:OJ**************@TK2MSFTNGP09.phx.gbl...
>> >> like this:
>> >>
>> >> this.txtUserName.Attributes.Add("onkeydown","if((e vent.which &&
>> > event.which
>> >> == 13)||(event.keyCode && event.keyCode ==
>> >> 13)){document.Form1.cmdLogin.click();return false;}else return
>> >> true;");
>> >>
>> >> that code rendered javascript to the client OK. Now that I upgraded to >> >> ASP.NET 2 Beta 2 it is rendering &amp;&amp; instead of &&, so clients > are
>> >> getting this instead:
>> >>
>> >> if((event.which &amp;&amp; event.which == 13)||(event.keyCode
> &amp;&amp;
>> >> event.keyCode == 13)){document.Form1.cmdLogin.click();return
> false;}else
>> >> return true;
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> "Patrice" <no****@nowhere.com> wrote in message
>> >> news:uL**************@TK2MSFTNGP09.phx.gbl...
>> >> > How do you render your scripts ?
>> >> >
>> >> > Patrice
>> >> >
>> >> > --
>> >> >
>> >> > "Alex D." <al********@hotmail.com> a écrit dans le message de
>> >> > news:uq**************@TK2MSFTNGP10.phx.gbl...
>> >> >> How can I stop asp.net from rendering XHTML istead of HTML?
>> >> >> My javascripts are rendering wrong because of that. It is rendering >> > &amp;
>> >> > to
>> >> >> clients instead of &.
>> >> >> Any help?
>> >> >> Thanks,
>> >> >> Alejandro.
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 19 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Peter Rohleder | last post: by
59 posts views Thread by Philipp Lenssen | last post: by
32 posts views Thread by jp29 | last post: by
16 posts views Thread by Mcginkel | last post: by
82 posts views Thread by Buford Early | last post: by
2 posts views Thread by Joris Janssens | last post: by
11 posts views Thread by Tomek Toczyski | last post: by
11 posts views Thread by Michael Powe | last post: by
10 posts views Thread by Robert Huff | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.