Click here to Skip to main content
15,894,540 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
Dear All,
I am getting problem in c# code to assign below string but its not proper working with single quotes.

string HighSlide = @"<a style='border: none;' href='CompanyMaster.aspx?popup=true'<br />
                                        önclick='return hs.htmlExpand(this, { objectType: 'iframe', align: 'left', width: 810, height: 520 });'><br />
                                       " + e.Day.Date.Day + "</a>";

When I see this line on browser it generate like below string.

string HighSlide = @"<a style='border: none;' href='CompanyMaster.aspx?popup=true'
                                         önclick='return hs.htmlExpand(this, { objectType: " + "''" + @"iframe" + "\'" + @", align: " + "\'" + @"left" + "\'" + @", width: 810, height: 520 });'>
                                       " + e.Day.Date.Day + "</a>";

Please help to correct for the same.

Thank you in advanced.
Posted
Updated 27-Jun-14 1:52am
v3
Comments
[no name] 27-Jun-14 8:11am    
Why do you escape the single quote characters sometimes and sometimes not?
Timberbird 27-Jun-14 8:34am    
It appears that in this line:
önclick='return hs.htmlExpand(this, { objectType: 'iframe', align: 'left', width: 810, height: 520 });'
you have single quotes inside single quotes. Try to resolve it, for example, by replacing first single quotes with double quotes:

önclick=""return hs.htmlExpand(this, { objectType: 'iframe', align: 'left', width: 810, height: 520 });""

("" generates double quotes in verbatim - i.e. @"..." - strings).
Bhanu Pratap Verma 27-Jun-14 8:43am    
I need to make the url like that.
TcJoshJohnson 27-Jun-14 12:57pm    
It doesn't "need" to be written that way as it is not proper syntax. This has nothing to do with C#, it is your HTML/JavaScript syntax that is incorrect. You need to either replace the single quotes from onclick with double quotes (as previously suggested) or replace the single quotes in the object literal with double quotes. The same would be true if you hard-coded this HTML snippet in an HTML document.
ZurdoDev 27-Jun-14 21:51pm    
You are correct. I would suggest posting as solution.

You need to either replace the single quotes from onclick with double quotes (as previously suggested by Timberbird) or replace the single quotes in the object literal with double quotes. The same would be true if you hard-coded this snippet in an HTML document.
 
Share this answer
 
Dear All,
I got the solution as I used &#39 prefix and suffix when I got the error.

example : &#39frame&#39 Its will automatically generate like 'frame'.

Thank You very much for your help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900