Monday, April 27, 2009

Setting TextBox Focus when using UpdatePanels

Try as I might TextBox1.Focus() would not give TextBox1 focus after an AsyncPostBack. Placing a breakpoint on that particular like of code showed that the code was executing, but alas... no blinking cursor. The solution to this problem is to use the ScriptManagers Focus()! ScriptManager1.SetFocus(TextBox1) gave me the results I was looking for.

Wednesday, April 15, 2009

Ways to fix PageRequestManagerParserErrorException

I created a web app that retrieves data from a binary column in sql server. In order to convert the data in that column I created an HttpHandler, but I had to pass an ID to the HttpHandler to pull the right row from the database. I decided to pass the ID via the session, but once I added the code for the Session variable I started getting this weird error the very first time I would run my app: "Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. comonn causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled."

I did a lot of looking around on the interwebs and found two sites that eventually landed me a solution I was happy with. This first blog suggested adding EnableEventValidation="False" to the top of the .aspx page, which did stop my error, but I wasn't comforatable doing this. I did some searching through the comments of this second blog and found out that all I needed to do was "initialize" my session variable, and that ended up working really well for me.