I have an UltraWebGrid nested within an Infragistics WebPanel on a page and would like to dynamically set the UltraWebGrid's SkinId based on an IsReadOnly property.
On the page's Page_PreInit event I have the following:
protected void Page_PreInit(object sender, EventArgs e){ if(IsReadOnly) ultraWebGrid.SkinID = "GridReadOnly";}
When the code runs, the ultraWebGrid object returns a null object exception when it is nested within the WebPanel. If I place the ultraWebGrid object outside the WebPanel the SkinId is set to "GridReadOnly" as desired.
How do I dynamically set the SkinId of an ultra web grid when it is nested within an InfragIstics web panel?
Wow, this turns into a pretty complex problem then. I think the best solution would be to turn the grid into a dynamic control. You can use a placeholder control inside of the WebPanel. On the page_init event you can call EnsureChildControls on the page, which should build the placeholder control. At that point, create your grid and set the SkinID, then add it to the PlaceHolder's childcontrols collection.
Hope this helps,
-Tony
I have already tried both of these approaches, but:
Assigining the SkinId property in the ultrawebgrid's OnInit event gives the error "The 'SkinId' property can only be set in or before the Page_PreInit event for static controls. For dynamic controls, set the property before adding it to the Controls collection."
And the "EnsureChildControls" method is not exposed on the Infragisitcs WebPanel control (version 8.2).
pre-init is too early in the page lifecycle to be accesing a child control. Most child controls/templates aren't created until post-init. You could attach an event handler to the WebGrid's OnInit event, and assign the property there. Alternatively, you can usually force creation of childcontrols by calling "EnsureChildControls", which is a framework method available off of every Control object.