Control is Null : Please Help

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
 
J

Jonathan Wood

Doh!

Problem solved: Once again bitten by caching--this time the control was
caching but not the master page. The result: the master page found the
control to be null.

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top