A usercontrol uses the cache as follows: <% @ Control Language = "C #" autoeventwireup = "true" codefile = "ucindexbureaumap. ascx. cs"
Inherits = "include_ucindexbureaumap" %>
<% @ Outputcache duration = "60" varybyparam = "NONE" %>
On the page that calls this user control, when you adjust the visible attribute of this UC, "not..." appears ...... Instance reference error.
Protected void page_load (Object sender, eventargs E)
{
Try
{
Page. Title = pagebase. webname;
// If (! Page. ispostback)
{
Tgcontentlist. pagesize = pagebase. modulepagesize;
Lablocation. Text = getlocation ();
Strmoduleid = request. querystring ["moduleid"]. tostring ();
Ucnavbar1.strselectedmoduleid = strmoduleid. substring (0, 4). Replace ('A', 'B ');
If (strmoduleid = "a017001 ")
{
Ucbureaumap1.visible = true; // an error occurs here, And ucbureaumap1 is empty.
Tgcontentlist. Visible = false; // This tablegrid will not have an error
}
Else
{
Ucbureaumap1.visible = false;
Tgcontentlist. Visible = true;
Binddata ();
}
// Initsearchfield (strmoduleid );
}
}
Catch
{
Alertmsn. popmsn_close (0, pagebase. m_error_bad_param, false );
}
}
However, there is no such problem when I enter the reference page once or twice, but it will be wrong again when I try again.
This is because the cache is set in usercontrol, and my page returns different pages based on the input moduleid parameter. The difference between the two pages is that one shows ucbureaumap1 and the other shows tgcontentlist. therefore, when you access the page at a certain time, the page without ucbureaumap is cached. When you change the moduleid parameter, the cached page does not contain the ucbureaumap object. Therefore, an error occurs.
Cancel the user control cache or set the cached varybyparam attribute to solve the problem.