Space Needle
|
The article you are reading has moved! It is now available at: http://blog.tinisles.com/2005/11/space-needle/ |
|
The article you are reading has moved! It is now available at: http://blog.tinisles.com/2005/11/space-needle/ |
|
The article you are reading has moved! It is now available at: http://blog.tinisles.com/2005/11/viewing-the-locks-in-ms-sql/ |
select so.name, sli.*, sp.* from sysobjects as so join master..syslockinfo as sli on sli.rsc_objid = so.id join master..sysprocesses as sp on sp.spid = sli.req_spid where xtype = 'U'System tables reference:
Labels: mssql
|
The article you are reading has moved! It is now available at: http://blog.tinisles.com/2005/11/were-off-to-germany/ |
|
The article you are reading has moved! It is now available at: http://blog.tinisles.com/2005/11/tricky-dynamic-controls-in-asp-net/ |
A few months ago I ran into a problem at work that forced me to really read up on dynamic controls and VIEWSTATE. Creating Dynamic controls requires a good understanding of the sequence of events when a page is generated in ASP.NET. If you don't understand what is happening things can get real messy, real fast!
I've created an ultra simplified version of the UI I was attempting to create. Pretty simple, I've got a DropDownList inside a table, that is populated with a DataBind when the page is first loaded. When the user selects and option from the DropDownList, and clicks a button, insert a column into the table. The dropdown always remains in the last column. I followed the guidelines from the codeproject article: Dynamically Created Controls in ASP.NET. Some important lessons to be learned from the article:
The first time I clicked the button everything worked as expected. Second attempt: not so happy! My DropDownList has lost its contents! View an example of broken dynamic contols: DynamicTable1.aspx (source). My first thought was to remove the test for !IsPostback in the Page_Load, so the DropDownList is populated everytime. This causes the DropDownList to 'forget' its selected position with each postback, and SelectedIndexChanged doesn't fire anymore. Presumably because I'm resetting it in Page_Load, ASP.NET doesn't consider it changed? Things are starting to get ugly.
The first clue as to what was going wrong came when I moved the DropDownList out of the table. Everything works! View an example of the working dynamic contols: DynamicTable2.aspx (source).
Some more research brings me to a really good article on the page events: Page Events: Order and PostBack by Paul Wilson. Important to note here is the order in which ASP.NET 'remembers' the contents on the DropDownList, and repopulates it.
Here is the order in which things are happening. First time we load the page:
The mismatch of control trees can be demonstrated by switching ASP.NET Trace on.
The solution was to move the RecreatePersistedControls to a place earlier in the process. As Paul Wilson says: "The best use of this method (LoadViewState) is to restore any dynamic controls you created in events, based on values you must manually save in ViewState, which is now available to use.". Perfect - moved RecreatePersistedControls into an overriden LoadViewState like this:
protected override void LoadViewState(object savedState) { base.LoadViewState (savedState); _persisted = (ArrayList)ViewState["persisted"]; RecreatePersistedControls(); }
View the completed demo: DynamicTable3.aspx (source)
|
The article you are reading has moved! It is now available at: http://blog.tinisles.com/2005/11/handy-web-reference-links/ |