Strange Behaviour with dynamic controls and postback processing
-
Hello, I came across something strange and I wonder whether anyone might know why it occurs? I have a page populated with dynamic controls. Ever time a postback occurs the controls are recreated with the same ids, before postback processing occurs, so that the controls are redisplayed with their values from the previous postback. (An aside: I'd be very interested to know how ASP.NET does this postback processing?). Before anyone comments, I am doing this because the page is too complicated to do any other way (I tried it using a repeater but got stuck once I started to building dynamic controls, including controls that generate events, within dynamic controls within a repeater!). It turned out to be easier to do this as a flat page of many dynamic controls and it does work. However, here was the strange behaviour. If I named a dynamic control, say a textbox with an id that contained a colon (:) any value I put in it is not kept across postbacks. If I replace the colon with an underscore (_) then the value is kept. So, why does the : cause a problem? Does it have some sort of special meaning for post-back processing? Regards, Matt Matt Daley Imutome Limited Bristol, United Kingdom matt.daley@imutome.com
-
Hello, I came across something strange and I wonder whether anyone might know why it occurs? I have a page populated with dynamic controls. Ever time a postback occurs the controls are recreated with the same ids, before postback processing occurs, so that the controls are redisplayed with their values from the previous postback. (An aside: I'd be very interested to know how ASP.NET does this postback processing?). Before anyone comments, I am doing this because the page is too complicated to do any other way (I tried it using a repeater but got stuck once I started to building dynamic controls, including controls that generate events, within dynamic controls within a repeater!). It turned out to be easier to do this as a flat page of many dynamic controls and it does work. However, here was the strange behaviour. If I named a dynamic control, say a textbox with an id that contained a colon (:) any value I put in it is not kept across postbacks. If I replace the colon with an underscore (_) then the value is kept. So, why does the : cause a problem? Does it have some sort of special meaning for post-back processing? Regards, Matt Matt Daley Imutome Limited Bristol, United Kingdom matt.daley@imutome.com
I'm not 100% sure on this, but it might help you out. I believe that : are used by the .Net Runtime when a control implements the INaming interface to ensure that all child controls have a unique id within the web page. Such as in the data grid control. The child control's uniqueId becomes ParentId:ChildId. When you use the : in your id, you may be confusing the .net runtime to try and look for a parent control that does not exist, so it never finds your control. HTH