Link to home
Start Free TrialLog in
Avatar of dguillen
dguillenFlag for United States of America

asked on

How can I turn off eventvalidation from code behind?

I've created an extension method to allow panels in my web application to rendertoHTML on demand.
Unfortunately to do it as I am, requires that EventValidation is turned off.  I don't want to turn it off for the entire site, and I do not want to have to know before hand to turn it off in the page direction.

Surely there is a way to turn it off as needed, then turn it back on after I'm done?  It seems more secure that way.
<System.Runtime.CompilerServices.Extension()> _
  Public Function RenderedOutput(ByVal c As System.Web.UI.WebControls.Panel) As String
     
        Dim SB As New System.Text.StringBuilder()
 
 
        Using swr As New System.IO.StringWriter(SB)
            Using htmltw As New System.Web.UI.HtmlTextWriter(swr)
                c.RenderControl(htmltw)
                Return SB.ToString()
            End Using
        End Using
 
 
 
    End Function

Open in new window

Avatar of carlnorrbom
carlnorrbom
Flag of Sweden image

Hi,

As far as I know You can't explicitly turn off event validation from code behind. You need to do it at page level declaratively in the page directive or in the <pages> configuration section of the web.config.

I guess one way around it could possibly be to craft some sort of Http utility to trap the rendered html before outputting it to the page and rewrite the page directive if a certain condition is met. I don't have access to my dev box at the moment but will look into it as soon as I can. Not sure about this though!

/Carl.
Avatar of dguillen

ASKER

what about if you create a page on the fly?
 it feels "weird" the idea that you can't control the site through code, you have to do it through special markup, it seems to me that if you generate pages dynamically they'd have given a way to do it outside of modifying the web.config!
did you try:

validator.Enabled = false

and/or

validator.EnableClientScript = false

I'm sorry MikeMCSD, I think you're thinking of form validator controls, where as I'm referring to the page Eventvalidation attribute.  Thanks though!
Hi,

Well, as far as I understand it's "By design"... I would probably still look into the HttpUtility option to catch and rewrite the rendered html before building the page and sending it off to the browser.

/Carl.
its definitely by design, but most things can be gotten around.  I'm not sure an httputility would work because the page directive is read by the server not streamed to the client? Unless you were thinking of something else?
ASKER CERTIFIED SOLUTION
Avatar of carlnorrbom
carlnorrbom
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well I'm going to accept this as the solution, essentially that it can't be done, or at least most likely can't be done.