views:

63

answers:

2

I know this is a very debated topic, and usually when you are thinking about this as a solution you might want to rethink your UI logic.

I know I can pass validation using ClientScriptManager.RegisterForEventValidation. But, I'd really like to know. Is it possible to remove event validation for a single control? Is there a way work around for this?

I'm modifying a DropDownList, from the client side after it's rendered.

A: 

I found it easier to replace the control with the HTML equivalent with runat="server", you can then retrieve the value the of old fashion way with Request.Forms["id"]. There will be no validation done, so be careful on storing or processing the data.

The other option is to override the Render on the page and use Page.ClientScript.RegisterForEventValidation with all the possible answers (not nice). something like this

    protected override void Render(HtmlTextWriter writer)
    {
        this.Page.ClientScript.RegisterForEventValidation(ddlRisk.ID, "a");
        this.Page.ClientScript.RegisterForEventValidation(ddlRisk.ID, "b");
        this.Page.ClientScript.RegisterForEventValidation(ddlRisk.ID, "c");
        base.Render(writer);
    } 
Podge
If you read the question, I am aware of this method. But implies knowing the values that are going to be added on the client side before the control renders, which I don't.
Raúl Roa
A: 

The short answer to your question is: No, there is no way to do this. You must disable EventValidation for the entire page.

There are various workarounds... If you really don't want to disable EventValidation, store the selected value in a hidden field and restore the state of the DropDownList (or maybe just clear selection?).

If you need all the values added client-side, you have to send those up using some other method anyway, because they will not be present in the server-side control. Those values are not posted!

Bryan
After trying different things I came up with the same answer to my question.
Raúl Roa