|
 |
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|

March 5th, 2010, 01:47 PM
|
Authorized User
|
|
Join Date: Feb 2008
Location: Tareem, Hadramout, Yemen.
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
Problem with "HttpUtility.HtmlEncode()"
Code [1]
Code:
Response.Clear();
Response.Write(@"document.write(""<html><body>case 1) Worked well</body></html>"");");
Response.End();
The above code prints
Code [2]
Code:
document.write(<html><body>case 1) worked well</body></html>");
and then it's called by a javascript as external javascript file, as below
Code [3]
Code:
<script type="text/javascript" src="http://localhost:52027/Work+notWork/Default.aspx"></script>
===================
But when I change the Code [1] to the following, it does not work.
Code:
Response.Clear();
Response.Write(HttpUtility.HtmlEncode(@"document.write(""<html><body>case 2) worked well</body></html>"");"));
Response.End();
The difference above is using the "HttpUtility.HtmlEncode", but I must use it, so what should I do to discover problem?
For more details, run the following and touch waht I mean
http://www.tareemnet.com/work+notwork.rar
Last edited by msman88; March 5th, 2010 at 01:54 PM..
|

March 5th, 2010, 05:01 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
Why did you think that "I must use it"? Note: what you are trying to encode is javascript, and after encoded, it's not valid javascript any more.
Last edited by PeterPeiGuo; March 5th, 2010 at 05:04 PM..
|

March 5th, 2010, 05:09 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I don't understand your problem. If case 1 works, then use it. Why do you HAVE to use HtmlEncode?
Basically encoding the document.write line as HTML entities means its not valid javascript any more.
You're not trying to do this are you?
Code:
Response.Write("document.write(\"" + HttpUtility.HtmlEncode(@"document.write(""<html><body>case 2) worked well</body></html>"");") + "\");");
|

March 5th, 2010, 05:14 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
You HtmlEncode the stuffs that will otherwise confuse the "receiving end", but javascript is entirely valid "as is" when included as part of HTML.
On a separate page, it is not a good practice to include javascript as part of html.
|

March 13th, 2010, 03:09 AM
|
Authorized User
|
|
Join Date: Feb 2008
Location: Tareem, Hadramout, Yemen.
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
Mr.you are near of idea.
I can clarify more...
What I actually I want to get is same as the following:
http://ads.adbrite.com/mb/text_group...s=3732385f3930
It contains <html> codes, and it's valid javascript.
|

March 14th, 2010, 12:54 PM
|
Authorized User
|
|
Join Date: Feb 2008
Location: Tareem, Hadramout, Yemen.
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
Hey!! Where are you wrox Professionals?
|

March 14th, 2010, 01:17 PM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
|

March 14th, 2010, 01:37 PM
|
Authorized User
|
|
Join Date: Feb 2008
Location: Tareem, Hadramout, Yemen.
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
Mr. Imar, if you are unable, please keep silent.
|

March 14th, 2010, 01:38 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
I think you misunderstood some of the replies above. Let's stay focused on the problem, and remember people are helping out of their kindness. Couple of things:
1) Yes, the link you give is a javascript containing code that generates html document or at least portion of it. The content of that javascript is served up by some PHP code;
2) If you want the same thing, the simplest way is to have the content (assume static) in a file and simply serve it as is;
3) You tried to generate that javascript from a piece of C# code, is that really necessary? If not, do what's mentioned in above point 2. Don't make things more difficult than needed.
4) If it's truly necessarily to generate from C#, read some of the above replies again, and try to understand what people said. All they said was: don't html encode your javascript portion, and the HtmlEncode() call away.
|
The Following User Says Thank You to PeterPeiGuo For This Useful Post:
|
|

March 14th, 2010, 01:39 PM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
That's exactly my point. If people don't respond, they're probably busy. Posting "bump" messages clutters up the forum and people's mail boxes and generally decreases your chances of someone replying....
Imar
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |