Range Validator’s Whacky Default

Just a quick tip to hopefully save someone out there a little bit of time… If you add range validator to your ASP.NET page that is checking a numerical range (e.g. 10 min to 100 max) make sure you set the Type of the range validator to Integer…  If you just say 10 to 100 without setting it, you’ll set some whacky results since it defaults to Type=String for some reason…

Page keep scrolling to the top on PostBack? No problem.

If you’re like me, you don’t like your page to scroll all the way back to the top when you click anything that causes a postback now that you’re already scrolled down a screen or two.  So how do you fix this, well, it’s actually really simple.  Just add SmartNavigation=”true” to your page directive on your .aspx pages like so:

<%@Page SmartNavigation=true%>

If you happen to want this enabled on all of your pages, then add the following inside the system.web node of your web.config file:

<system.web>
     <pages smartNavigation=”true”>
</system.web>

Event handler not firing? AutoPostBack

I keep running into people having this problem, so I’m going to put this out there in the hopes that someone will find this BEFORE they pull out their hair…

If you have an event handler that is not firing in your ASP.NET page and the control that is supposed to be firing it is a textbox, drop down list, checkbox, etc. (events like OnChanged would be what you would most likely have this problem with) then you MUST set the “AutoPostBack” property of the form control(s) to true…  If you don’t do this, it will never fire your events because it will not come back to the server for anything until you click a button or something else that causes a postback happens. 

Keep in mind that causing a postback on events like these could cause a good bit more traffic than you think and it will also cause the page to jump back to the top if you don’t use the tip from my next blog entry…