Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
| Search | Today's Posts | Mark Forums Read
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2010, 01:47 PM
Authorized User
Points: 437, Level: 7
Points: 437, Level: 7 Points: 437, Level: 7 Points: 437, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2008
Location: Tareem, Hadramout, Yemen.
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
Question 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..
 
Old March 5th, 2010, 05:01 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

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..
 
Old March 5th, 2010, 05:09 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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>"");") + "\");");
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 5th, 2010, 05:14 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

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.
 
Old March 13th, 2010, 03:09 AM
Authorized User
Points: 437, Level: 7
Points: 437, Level: 7 Points: 437, Level: 7 Points: 437, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2008
Location: Tareem, Hadramout, Yemen.
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
Post

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.
 
Old March 14th, 2010, 12:54 PM
Authorized User
Points: 437, Level: 7
Points: 437, Level: 7 Points: 437, Level: 7 Points: 437, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2008
Location: Tareem, Hadramout, Yemen.
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Hey!! Where are you wrox Professionals?
 
Old March 14th, 2010, 01:17 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Return data type
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 14th, 2010, 01:37 PM
Authorized User
Points: 437, Level: 7
Points: 437, Level: 7 Points: 437, Level: 7 Points: 437, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2008
Location: Tareem, Hadramout, Yemen.
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Mr. Imar, if you are unable, please keep silent.
 
Old March 14th, 2010, 01:38 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

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:
msman88 (March 14th, 2010)
 
Old March 14th, 2010, 01:39 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulties with "web.config" and "ASPNETDB" CFRham BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 2 July 3rd, 2010 10:19 AM
Need code corrections "get sub or function not defined" error" bluesboytoo Excel VBA 1 October 22nd, 2009 11:12 PM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.