J
Jonathan Wood
Greetings,
I have a master page with a web user control. The web user control is added
to the master page using markup:
<%@ Register src="Controls/Categories.ascx" tagname="Categories"
tagprefix="uc2" %>
<div id="sidebar">
<p class="boxheader">Categories</p>
<div class="box">
<uc2:Categories ID="Categories1" runat="server" />
</div>
</div>
The master page needs a public method to modify this web user control, which
the content page can call from its load event.
So I added a public method but found the control was null when the method
was called. So I changed it to store the values and actually modify the
control in the master page's load event. But I found the control was still
null. So I changed it to actually modify the control in the master page's
prerender event.
protected int _category = -1;
protected bool _isMainCategory = false;
public void SetCategory(int category, bool isMainCategory)
{
_category = category;
_isMainCategory = isMainCategory;
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (_category != -1)
{
Categories1.SelectedCategory = _category;
Categories1.SelectionIsMainCategory = _isMainCategory;
}
}
But I get an error that Categories1 is STILL null, even in the PreRender
event.
Can anyone spot why? The control works and displays normally on the page.
But all documentation I could find suggests all master page controls should
be loaded by the time the master page's prerender event is called.
Any tips greatly appreciated.
Jonathan
I have a master page with a web user control. The web user control is added
to the master page using markup:
<%@ Register src="Controls/Categories.ascx" tagname="Categories"
tagprefix="uc2" %>
<div id="sidebar">
<p class="boxheader">Categories</p>
<div class="box">
<uc2:Categories ID="Categories1" runat="server" />
</div>
</div>
The master page needs a public method to modify this web user control, which
the content page can call from its load event.
So I added a public method but found the control was null when the method
was called. So I changed it to store the values and actually modify the
control in the master page's load event. But I found the control was still
null. So I changed it to actually modify the control in the master page's
prerender event.
protected int _category = -1;
protected bool _isMainCategory = false;
public void SetCategory(int category, bool isMainCategory)
{
_category = category;
_isMainCategory = isMainCategory;
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (_category != -1)
{
Categories1.SelectedCategory = _category;
Categories1.SelectionIsMainCategory = _isMainCategory;
}
}
But I get an error that Categories1 is STILL null, even in the PreRender
event.
Can anyone spot why? The control works and displays normally on the page.
But all documentation I could find suggests all master page controls should
be loaded by the time the master page's prerender event is called.
Any tips greatly appreciated.
Jonathan