Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 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 .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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..
  #2 (permalink)  
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..
  #3 (permalink)  
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?
  #4 (permalink)  
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.
  #5 (permalink)  
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.
  #6 (permalink)  
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?
  #7 (permalink)  
Old March 14th, 2010, 01:17 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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!
  #8 (permalink)  
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.
  #9 (permalink)  
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)
  #10 (permalink)  
Old March 14th, 2010, 01:39 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.