views:

40

answers:

2

I recently installed Visual-Web-Developer 10 and open my old asp.net 3.5 solution in it and converted it to asp.net 4 solution. every thing is working fine exept one strange problem: suddenly all chars like: ' or " in header script code become: ' or " and this making all my javascript do not work and give error in all my solutuin pages.

i tryed to save the page in different encoding but it did not help: here is example of what happening: in server side code:

HtmlGenericControl Include = new HtmlGenericControl("script");
    Include.Attributes.Add("type", "text/JavaScript");
    Include.InnerText = "browser = \"ie\"; browserVer = '8'; bodyDir = 'rtl'; adverID = '123'; webKind = 'adver';";
    Page.Header.Controls.Add(Include);
    Include.Dispose();

on user side i get:

<script type="text/JavaScript">browser = &quot;ie&quot;; browserVer = &#39;8&#39;; bodyDir = &#39;rtl&#39;; adverID = &#39;123&#39;; webKind = &#39;adver&#39;;</script>

big thanks for any halp chainan

+3  A: 

Use the InnerHtml property instead, to add the contents of the script. The InnerText gets converted..

Quote from InnerText

Unlike the InnerHtml property, the InnerText property automatically encodes special characters to and from HTML entities. ...

Gaby
You do know the difference between formatting code and quotations, don't you? ;)
Marcel Korpel
@Marcel, i do :) .. but the initial quote i wanted to post had encoded entities inside it, and the quotation converts them, while the code does not.. kind of like the OP problem ..
Gaby
thanks a lot that solved my problam
in asp.net 4 you can use litiral control in header section as well
+2  A: 

Use InnerHtml property instead of InnerText.

*"The InnerHtml property does not automatically encode special characters to and from HTML entities. HTML entities allow you to display special characters, such as the < character, that a browser would ordinarily interpret as having special meaning. The < character would be interpreted as the start of a tag and is not displayed on the page. To display the < character, you would need to use the entity &lt;.

Tim Schmelter