Ok, I’ve found a nice little bug, it’s rather simple.
Have a web form with an update panel (regardless of how the update panel is setup). Also add a place holder inside the update panel.
Then build your self a nice little user control and place a simple text box on it, then add a simple Compare Validator. Have the Validator do a data type check on double or something. Add another textbox so you have one to go to after testing the first textbox. Also put in a button, it doesn’t need to do anything, just a simple ASP button.
Now on load of the page, have the user control get dynamically created via “LoadControl” method. Have it loaded into the controls collection of the Placeholder in the update panel.
Now enter some alpha text into the text box and note how the validator won’t work. Also note how when you click the button which BTW is inside a user control which is in a panel which is in an update panel and has no code at all behind it. Notice how it will cause whole page post back.
I believe this is because of some short circuits the update panel and instead by passes it and acts as if it’s directly on the form.
Hence this statement direct out of the MSDN Doc’s:
When you load a control into a container control, the container raises all of the added control's events until it has caught up to the current event. However, the added control does not catch up with postback data processing.
Now do the same thing but instead of loading the user control we just place the user control inside the update panel. Now run and see how it works, you will find everything now works and the whole page does not post back when the button is clicked.
This is the expected behavior.
Hence the lesion learned here is not to use dynamic user controls with update panels.
In my next post I will go over how to do a lot of the things you would do with the Ajax framework, all without Ajax.
For those of you who might be wondering, I’ve been having my share of fun with the road home project in Baton Rouge, Louisiana. If you have never been to Baton Rouge, well you are not missing anything, trust me!
The road home project is a series of applications and programs for getting people back to Louisiana. As some of you might now, after the storms people have been spread across the country. This project was put in place to help people back to their home sate and home cities/towns. It’s quite an interesting project to say the least.
I’ll be in Tampa doing a talk or two at the Tampa Code camp this July 14th, see you there!