Thomas’ Developer Blog

November 15, 2008

RegisterForEventValidation and enableEventValidation

Ok first off… NEVER disable eventvalidation! This is for your own good. I know it’s very tempting to just type in enableeventvalidation=”false” and have the script work just fine. It’s a major security issue though and so it’s just best to learn it right the first time and fix it right!

So why does this pesky error appear at times? There are a few reasons in my case, because I had a clientside script being run from a server control. Which caused some messy conflicts. To sold this error it is actually really easy. Just include the following code in your script:

        Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            Page.ClientScript.RegisterForEventValidation(tbxSearch.uniqueid)
            MyBase.Render(writer)
        End Sub

And that’s it! Ok, maybe I should explain it. Generally you have to edit the script on the render phase. If you don’t know the page lifecycle…. learn it! You’ll need it! Just google it and you’ll find a great description on msdn.

So generally we override the render phase. Thus the keyword overrides in the code. The MyBase.Render(writer) line of code is basically…. what normally happens. In this case right before the render phase goes through we inject a line of code to say, “Hey, ignore this control! It’s safe!” and then the clientscriptmanager will process that control and let it slide pass eventvalidation. Now to do this you have to do it through page.clientscript and use the registerforeventvalidation method to find the specific control you need to allow.

After that test out the page and there shouldn’t be any problems! oh btw I do typically disable ValidateRequest myself. This generally prevents users from submitting information like “<script…..” into forums and such. Which if you are using proper coding methods you shouldn’t need to run these training wheels. Eventvalidation is a whole other story since it’s a lot more work to enforce it strictly behind code.

Advertisements

28 Comments »

  1. In theory, this should work, but not for me! :(

    I am using an Update Panel that has an asp:panel inside it with a button. The button becomes visible after postback if a checkbox is checked. When the button is clicked after being visible, I get the error still even after applying this code.

    Any hints?

    Comment by Joel — May 28, 2009 @ 6:36 am

  2. Besttman

    Comment by Besttman — February 4, 2013 @ 12:02 am

  3. Though laying tile in the bathroom may seem a difficult task for those who have never done it before, it may have both advantages & disadvantages.
    [url=http://bailiffsmercantile.com/]How to lay tile in the bathroom floor?[/url]

    Comment by TileMaster — April 10, 2013 @ 4:13 am

  4. hi

    Comment by MayorryCourn — August 15, 2013 @ 4:38 pm

  5. http://recepti-dlya-multivarki.besaba.com/sitemap.php
    recepty dlya multivarki 0517

    Comment by middlazuc — November 14, 2013 @ 11:47 pm

  6. http://template.twelife.ru/psd-shablon-bethlehem-multipurpose-church-psd/
    recept mannoi kashi v multivarke

    Comment by rencame — November 18, 2013 @ 3:05 pm

  7. а

    Comment by Onetadeert — December 6, 2013 @ 8:31 am

  8. hello!

    Comment by Sn — January 12, 2014 @ 11:39 pm

  9. здравствуйте, мне показалось будет классно показать всем
    это нечто, что живет у меня дома:
    [img]http://all4nokia.com/cats/2.jpg[/img]
    Маркиз 1.3 года

    милашка, правда?
    покажите своих питомцев!

    Comment by Apram — May 7, 2014 @ 9:23 pm

  10. Howdy are using WordPress for your blog platform?
    I’m new to the blog world but I’m trying to get started and set up my own. Do you
    require any html coding knowledge to make your own blog?
    Any help would be greatly appreciated!

    Comment by how to configure best best dsl how to configure modem — August 28, 2014 @ 10:54 pm

  11. Pretty nice post. I just stumbled upon your weblog and
    wished to say that I have truly enjoyed browsing your
    blog posts. After all I’ll be subscribing to your rss feed and I hope
    you write again soon!

    Comment by how to configure best cable best dsl modem for xbox — September 4, 2014 @ 5:04 pm

  12. Great post. I was checking continuously this weblog and I am
    impressed! Very useful info specially the last part :) I take care of such
    info a lot. I used to be looking for this certain information for a long time.
    Thanks and good luck.

    Comment by how to configure best buy modem for comcast internet — September 8, 2014 @ 5:53 am

  13. I’m now not sure where you’re getting your information, however good topic.
    I needs to spend a while studying much more or understanding more.
    Thanks for magnificent info I used to be on the lookout for this information for my mission.

    Comment by how to configure best best dsl best comcast modem for — September 19, 2014 @ 4:46 am

  14. I think this is among the most vital info for me. And
    i am glad reading your article. But wanna remark on some general things,
    The website style is ideal, the articles is really great :
    D. Good job, cheers

    Comment by how to configure best best best cable modem for comcast — September 20, 2014 @ 1:54 am

  15. I think this is among the most important information for me.
    And i am glad reading your article. But should remark on some general things, The
    website style is ideal, the articles is really excellent : D.
    Good job, cheers

    Comment by how to configure best arris best cable modem for comcast — September 20, 2014 @ 11:00 am

  16. Aw, this was a very good post. Finding the time
    and actual effort to create a superb article… but what can I say… I hesitate a whole lot and never manage to get nearly anything done.

    Comment by how to configure best buying a best docsis 3 cable modem — September 21, 2014 @ 5:52 am

  17. Pretty section of content. I just stumbled upon your weblog and in accession capital
    to assert that I acquire actually enjoyed account your blog posts.
    Any way I’ll be subscribing to your feeds and even I achievement you
    access consistently rapidly.

    Comment by how to configure best cable best dsl modem for xbox 360 — September 21, 2014 @ 3:10 pm

  18. I believe everything published was very reasonable. But, what about this?
    suppose you wrote a catchier post title? I ain’t suggesting your content isn’t
    solid, however what if you added a post title to possibly grab
    a person’s attention? I mean RegisterForEventValidation and enableEventValidation | Thomas’ Developer Blog is
    kinda boring. You should look at Yahoo’s home page and note how they create article headlines to get people to click.
    You might add a video or a related pic or two to grab people interested
    about what you’ve written. Just my opinion, it could make your website a little bit more interesting.

    Comment by how to configure best best comcast best dsl modem for xbox — September 23, 2014 @ 3:26 am

  19. Pretty great post. I just stumbled upon your weblog and wanted to say
    that I’ve truly loved browsing your weblog posts.
    In any case I’ll be subscribing for your feed and I am hoping you write once more very soon!

    Comment by how to configure best best wireless best wireless cable modem — September 23, 2014 @ 12:48 pm

  20. My brother recommended I might like this blog.
    He was entirely right. This post truly made my day.

    You can not imagine simply how much time I had spent for this information! Thanks!

    Comment by dziewczyny na telefon — September 23, 2014 @ 1:08 pm

  21. Great article. I will be facing many of these issues as well..

    Comment by how to configure best cable best comcast modem for xbox — September 26, 2014 @ 5:52 am

  22. I would like to thank you for the efforts you have put in penning this website.
    I am hoping to see the same high-grade blog posts from you later on as well.
    In fact, your creative writing abilities has encouraged
    me to get my own website now ;)

    Comment by how to configure best cable modem for comcast internet — September 28, 2014 @ 4:22 am

  23. Hmm is anyone else having problems with the pictures on this blog loading?

    I’m trying to figure out if its a problem on my end or if
    it’s the blog. Any suggestions would be greatly appreciated.

    Comment by how to configure best cable best comcast modem for xbox — September 30, 2014 @ 9:56 pm

  24. Thank you for sharing your thoughts. I really appreciate your efforts and I will be waiting for your further
    post thanks once again.

    Comment by Il mondo dell’archeologia — October 5, 2014 @ 2:15 am

  25. http://ucoz-info.ru/

    Comment by DennisLeMA — January 8, 2015 @ 8:51 am

  26. The brand of Moda in pelle provides extremely stylish, durable and comfortable shoes.
    The Unitron website includes detailed description of the features and benefits from this product.
    1990’s – Bra became a highlight on women’s wardrobe.

    Comment by buty — April 5, 2015 @ 8:37 am

  27. Also, they have ruled the market due to their anatomical constructions
    of shoes that make the shoes anti-stress with special shock
    absorption system. All footwear at Bourne is hand-crafted especially by Opanka construction and the
    use of adhesives and machinery is minimal while creating the
    shoes, thus making the designs eco-friendly. Fresh pairs of UGG
    products arrive in latest designs and fake boots are replicas of
    these originals.

    Comment by sukienki — May 8, 2015 @ 7:07 am

  28. You can adopt their styles to suit yours; this is one of the best
    ways to determine the right fashion for you. They are going to almost any extent to look good and attractive.
    A new kind of wire mixed with natural fabrics,
    like cotton, provided the perfect adjustment to
    the body.

    Comment by potencja — September 2, 2017 @ 7:48 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: