Thursday, March 22, 2012

Why the content of my GridView wont show up when I populate them in onLoad?

I have an ASPX page loading a user control that loads other user controls dynamically.

The ASPX page loads the top level user control perfectly (let's call it setup.ascx), but the content of UserSetup.ascx (loaded into Setup.ascx) doesn't show up if I do the populating in OnLoad() but shows up perfectly if I do the population in OnPreRender(). Why? I'm loading UserSetup.ascx in one of the onClick methods in Setup.ascx

I've been trying to figure this out for 2 days, and I'm stuck!

BTW, I'm using a home brewed DataSource for the GridView and the way I load it looks something like this:


gridDataSource.DataSource = setupArray;
gridDataSource.DefaultSortProperty = "Name";
gridProperties.DataSourceID = "gridDataSource";

The funning thing is that if you debug on the line after

gridProperties.DataSourceID = "gridDataSource";
, gridProperties.Rows is 0 if I'm loading the data in onLoad, but 5 (the correct number) if I'm loading the data in onPreRender.

Thanks,

JasonFor what's worth, I have narrowed it down to this line:


gridProperties.DataSourceID = "gridDataSource";

It appears the Grid will only be populated if the above line is executed during PreRender.
Update:

I was unable to find the perfect solution so I ended up putting

gridProperties.DataSourceID = "gridDataSource";
in OnPreRender while the rest in OnLoad().

0 comments:

Post a Comment