jamietre / CsQuery

CsQuery is a complete CSS selector engine, HTML parser, and jQuery port for C# and .NET 4.
Other
1.16k stars 250 forks source link

CsQueryHttpContext Render ...value=""> being changed to ...value> - Attribute Minimisation ASP.NET Web Forms Error #135

Open CJCannon opened 11 years ago

CJCannon commented 11 years ago

Hi, I noticed that <option selected="selected" value="">All</option> is being rendered as <option selected="selected" value>All</option>

This is causing the following error on my production server (IIS 6):

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

but weirdly not happening on my dev server.

My workaround is not to use empty strings but is this a bug that can be fixed?

CJCannon commented 11 years ago

Nothing to do with IIS sorry!

But only getting the error on IE - not Firefox, Chrome or Opera - so it's something to do with IE...

So <option selected="selected" value> is causing the issue and IE is doing something not quite right and ASP.NET is throwing a wobbly. Please help!

CJCannon commented 11 years ago

I can also fix it using jQuery:

<script type="text/javascript">
    $(function () {
        $("option[value='']").attr("value", "");
    });
</script>
CJCannon commented 11 years ago

However

    Dim cqContext As CsQueryHttpContext = WebForms.CreateFromRender(page, renderMethod, writer)

    Amend(cqContext.Dom, HttpContext.Current.Request.Url.AbsolutePath)

    cqContext.Render(DomRenderingOptions.QuoteAllAttributes)

Doesn't render quotes for attributes with empty values - attribute minimisation is being applied.

Please can I have an option to turn off or prevent attribute minimisation?

jamietre commented 10 years ago

Sorry for taking so long to follow up on this one..

This should be fixed so CsQuery knows which attributes must have values and will render empty string for those attributes.