Posts Tagged ‘viewstate’
User controls are the source of a lot of headaches in C#. They have two major issues that tend to drive programmers a little mad. The first is that they don’t play nicely with the ViewState. Particularly once users start to nest and reorder user controls, the ViewState model (much of which is based on position within the page) starts to break down. In many cases programmers circumvent this little nightmare by simply disabling the ViewState on some controls.
The second issue is that user controls are in their own scope and don’t have immediate access to the rest of the page. That is both a blessing and a curse; good control design means that the controls should be fairly independent of each other but a more pragmatic developer will also note that user controls exist primarily so that numerous copies of the same thing can be easily created and that making entirely self contained controls leads to a lot of unnecessary duplication.
Fortunately there are workarounds for both of these issues. (more…)
My “learn C# project” at work has centered around creating a drag-and-drop portlet style system for the display of custom widgets. I’ve been using JQuery UI for the javascript functionality but the backend has been all custom C# work.
People familiar with C# know that C# supports the inclusion of user defined controls called WebControls. These are more or less very simple C# programs which can be man-handled by another bit of C# code. They’re handy for making your code modular: you might design a web-control that takes and validates a credit card number, for example.
But WebControls are notoriously tricky beasts and over the course of the last few weeks I’ve come to understand that one of the reasons for this is that they don’t behave quite the way you might expect them to when they are serialized and deserialized. (more…)