Solved

How can I turn off eventvalidation from code behind?

Posted on 2009-04-10
8
425 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:dguillen
  • 4
  • 3
8 Comments
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24118594
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.
0
 
LVL 1

Author Comment

by:dguillen
ID: 24118636
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!
0
 
LVL 16

Expert Comment

by:MikeMCSD
ID: 24118800
did you try:

validator.Enabled = false

and/or

validator.EnableClientScript = false

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:dguillen
ID: 24118965
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!
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24131159
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.
0
 
LVL 1

Author Comment

by:dguillen
ID: 24154351
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?
0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 24155730
Hi,

Yes I have given this some time and I have not been successful. I was able to supress the error message generated by the event validation using a custom httpmodule and overriding the BeginRequest event and then using context.Context.ClearError() but I don't see this as a viable solution in Your case.

/Carl.
0
 
LVL 1

Author Closing Comment

by:dguillen
ID: 31568995
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.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question