Reputation: 377
I have an asp.net web page.
Is there a possibility to just get 'real' single quotes client side?
Server side:
this.Attributes["onclick"] = "$('#button').click();";
Client side:
onclick="$('#button').click();"
gives an error.
Alert works just fine, i.e. Client side:
onclick="alert('hello#amp;39;);".
Seems like I need 'real' single quotes to work with jQuery.
Upvotes: 0
Views: 807
Reputation: 819
Is this standard ASP.NET, or ASP.NET MVC? It appears that the output is being escaped, but without sample code or more details I cannot be certain.
Your code example of
this.Attributes["onclick"] = "$('#button').click();";
How is that rendered from the server? From a control?
Updated
This attribute value encoding was introduced in .NET 4.0. If you must you can set the controlRenderingCompatibilityVersion
in your web.config to "3.5" see pages Element (ASP.NET Settings Schema) & PagesSection.ControlRenderingCompatibilityVersion Property.
Could you (instead of placing the onclick logic directly in the attribute value) record the function elsewhere and set the function name as the onclick value? Or register the click handler client side using jQuery?
Upvotes: 1