An example of a bug caused by ASP. Net user control caching

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.