PRB: AutoPostBack for the DropDownList Control May Not Work as Expected When You Use Caching and VaryByControl Is Set to DropDownList (822317)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework 1.1)
- Microsoft ASP.NET (included with the .NET Framework) 1.0
SYMPTOMSWhen you set the VaryByControl attribute of the @ OutputCache
directive to DropDownList in an ASP.NET page, the AutoPostBack property of
the DropDownList control may not work as expected.CAUSEYou can use the @ OutputCache directive attribute VaryByControl to cache multiple versions of user control output, based on a GET query
string or on form POST parameters. However, after the user control is cached, the
__doFormPost method is not generated for postback.
Registration of the postbackscript occurs on the OnPreRender method. However, the OnPreRender method of the cached control is not called when you cache the
user control. Therefore, when
the user control is cached, the __doFormPost method is not generated.WORKAROUNDTo work around this problem, call the GetPostBackEventReference method in the Page_Load event of an ASPX page. To work around the
problem that is discussed in the "More Information" section, modify the code of the Page_Load event as follows: Visual C# .NET Sample Code public void Page_Load()
{
DateTime Created = DateTime.Now;
CreatedStamp.InnerHtml = Created.ToString("r");
GetPostBackEventReference(this);
} Visual Basic .NET Sample Code Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Created As DateTime
Created = DateTime.Now
CreatedStamp.InnerHtml = Created.ToString("s")
GetPostBackEventReference(Me)
End Sub STATUS This
behavior is by design.REFERENCES For additional information,
click the following article numbers to view the articles in the Microsoft
Knowledge Base: 307225
INFO: ASP.NET Caching Overview
308378 HOW TO: Perform Fragment Caching in ASP.NET by Using Visual C# .NET
308645 HOW TO: Perform Fragment Caching in ASP.NET by Using Visual Basic .NET
For more information, visit the following
visit the following Microsoft Web site: For
information about ASP.NET caching and samples of ASP.NET caching from the ASP.NET QuickStart
guides, visit the following Microsoft Web site:
Modification Type: | Major | Last Reviewed: | 8/8/2003 |
---|
Keywords: | kbCaching kbServerControls kbForms kbControl kbWebForms kbprb KB822317 kbAudDeveloper |
---|
|