C# Avoid escaping characters whilst adding attributes to web control

Hello,

When I add an attribute to my web control with as value "http://www.zzz.com/page?param1=2¶m2=66", see code below, I get in my html : "http://www.zzz.com/page?param1=2&param2=66" Which is my problem. Is anyway to avoid having the "&" replaced by "&"?
Thanks

HtmlGenericControl m_ScriptLink = new HtmlGenericControl("script");
container.Controls.Add(m_ScriptLink);
m_ScriptLink.Attributes.Add("src","http://www.zzz.com/page?param1=2¶m2=66");
webgourAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

starlite551Commented:
Try it this Way..
HtmlGenericControl m_ScriptLink = new HtmlGenericControl("script");
container.Controls.Add(m_ScriptLink);
string link = "http://www.zzz.com/page?param1=2&param2=66";
if(link.Contains("&"))
{
     StringBuilder sb = new StringBuilder(link);
     sb.Replace("&","&");
     link = string.Empty;
     link = sb.ToString();   
}
m_ScriptLink.Attributes.Add("src",link);

Open in new window

0
starlite551Commented:
Or You can directly try this..
HtmlGenericControl m_ScriptLink = new HtmlGenericControl("script");
container.Controls.Add(m_ScriptLink);
string link = "http://www.zzz.com/page?param1=2&param2=66";
m_ScriptLink.Attributes.Add("src",link.Replace("&","&"));

Open in new window

0
starlite551Commented:
Sometimes you also get value such as " " you can do the same thing in that case too..
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

webgourAuthor Commented:
Thank you for your help, but that won't work, with your solution the replace occurs before the string is html encoded
0
Carl TawnSystems and Integration DeveloperCommented:
The problwem you will have is that all of the Html controls dump out there output using the HtmlTextWriter which will automatically escape html values. So, you're either going to have to override the Render method for the control (which you really don't want to be doing), or you can simply use a LiteralControl instead:
LiteralControl script = new LiteralControl();
script.Text = "<script src=\"http://www.abc.com/page?param=1&param2=1\"></script>";

container.Controls.Add(script);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
webgourAuthor Commented:
I've dealt with the problem however pretty much as you mention... Thanks for your answer u get your point ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.