all groups > asp.net building controls > october 2003 >
You're in the

asp.net building controls

group:

DataGrid rendering inconsistant with other web controls


DataGrid rendering inconsistant with other web controls Peter Blum
10/27/2003 1:57:31 PM
asp.net building controls: When a WebControl is set to Visible = false, the OnPreRender and Render
methods are both skipped. (Control.PreRenderRecursiveInternal skips
OnPreRender on children; Control.RenderControl skips Render on children.)

DataGrid always calls the OnPreRender event, even when the control is
contained in a Column whose Visible property is false or footer template
whose ShowFooter property is false.

Since OnPreRender is often used to register client-side scripts, and those
scripts often depend on the HTML created in the Render method, it makes
sense to block OnPreRender when the control will not be rendered. As a
result of the DataGrid's design, any custom control that generates such
client-side code may be break in the DataGrid when it would work fine
elsewhere. (In other words, expect JavaScript errors.) I could not find
anywhere in the .NET documentation stating that the Visible property will
cause the OnPreRender method to be skipped when false. However, the
documenation says the control will not be rendered when Visible = false.
Since OnPreRender is documented as preparing for the Render phase, I feel
this is really a bug.

The worst part of this that I cannot find any way for a web control to
detect that it will not be rendered. Normally, the Visible property on a
control is false when any parent's Visible property is false. In the
DataGrid, its still Visible=true even though the DataGridColumn containing
it is Visible=false. I'd like to find a low impact way of detecting this
control will not be rendered so it doesn't output its client-side script.
(Yes, I will make my client-side scripting more defensive but I'd like to
push for the server-side code working consistently.)

I'd like Microsoft's view on this and if nothing else, to get this issue
clearly documented.

--- Peter Blum
www.PeterBlum.com

Re: DataGrid rendering inconsistant with other web controls Peter Blum
10/28/2003 10:17:54 AM
Hi Luke,

We are in agreement on how the DataGrid operates and even the work around
that you describe. The reason I posted the message was because I believe
that the DataGrid has been implemented incorrectly in this matter and should
be evaluated for a fix.

I believe that any control created within a DataGridColumn whose Visible
property is false, should also get its own Visible property set to false.
(If you do this, Control.PreRenderRecursiveInternal will skip calling both
OnPreRender and Render, just as it does for all other controls.)

The work around you have suggested has side effects.
1. It causes JavaScript to be added to the page when its unnecessary,
increasing the page size.
2. It may require a different design to the client-side code, such as
testing for the missing HTML earlier in an initialization function.
3. Since it breaks from the standard, custom control developers will build
working code only to learn later, that it breaks in this particular case.
Why would these developers anticipate this problem?

If you feel that I should use a different channel to address this with
Microsoft development, please let me know what that channel is.

--- Peter Blum
www.PeterBlum.com
Email: PLBlum@PeterBlum.com

[quoted text, click to view]

RE: DataGrid rendering inconsistant with other web controls lukezhan NO[at]SPAM online.microsoft.com
10/28/2003 10:39:07 AM
Hi Peter,

When we set one coulmn to invisible in datagrid, the customcotrol's load
and prerender event will still be fired. This is caused by that the
customer's control's parents don't include the datagridcolumn object. A
work around is to add some script to the client script block you will add
to client, determine if the client HTML component exist, if so, the Visible
property should be True and we can go on for next script line; If not, we
can exit the script without doing any thing.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Re: DataGrid rendering inconsistant with other web controls lukezhan NO[at]SPAM online.microsoft.com
10/29/2003 9:25:33 AM
Hi Peter,

Thank you very much for this. I think it is a great idea for a future
product enhancement. I'd recommend that you forward the recommendation to
this web page:

http://register.microsoft.com/mswish/suggestion.asp?&SD=GN&LN=EN-US&gssnb=1

Thank you again,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Re: DataGrid rendering inconsistant with other web controls Peter Blum
12/1/2003 5:00:03 PM
Here's an update on this topic.

I consulted with Microsoft Tech and they passed the issue by the developers.
The developers felt this could be a bug in the DataGrid and have put in a
bug report with the hope that it will be fixed in ASP.NET 2.0.

--- Peter Blum
www.PeterBlum.com
EMail: PLBlum@PeterBlum.com

[quoted text, click to view]

Re: DataGrid rendering inconsistant with other web controls lukezhan NO[at]SPAM online.microsoft.com
12/2/2003 10:05:18 AM
Thank you for the share!

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
AddThis Social Bookmark Button