Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8003425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:38:45+00:00 2026-06-04T16:38:45+00:00

I have a System.Web.UI.UserControl in my application which is to be used to display

  • 0

I have a System.Web.UI.UserControl in my application which is to be used to display messages to the user, however after these messages are displayed to the user once I want them to clear (conditionally).

The simplified code I have now that I am trying to get to work is the following:

protected override void OnUnload(EventArgs e) {
if (_resetOnUnload) {
    divMessageBlock.InnerHtml = "";
    _resetOnUnload = false;
}
base.OnUnload(e);
}

However any changes to the view in the OnUnload event do not get transferred over on the next page load (form submit).

My question is how would I setup this user control to clear itself either before any messages can be added elsewhere or after the page has been rendered for the user and have stay that way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:38:47+00:00Added an answer on June 4, 2026 at 4:38 pm

    Try this. Set the viewstate to save _resetOnUnload and then load it. OnLoad can stay the same, testing whether or not to clear.

    protected override void OnLoad(EventArgs e) {
              base.OnLoad(e);
    
              if (_resetOnUnload) {
                     divMessageBlock.InnerHtml = "";
                     _resetOnUnload = false;
              }
       }
    
       protected override void LoadViewState(object savedState) {
              if (savedState != null) {
                     object[] myState = (object[])savedState;
                     _resetOnUnload = (bool)myState[0];
              }
       }
    
       protected override object SaveViewState() {
              object[] allStates = new object[]{ _resetOnUnload };
              return allStates;
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class UserControlBase that inherits System.Web.UI.UserControl and my user controls inherit UserControlBase
I have this c# user control class: public partial class UserControls_JsTop : System.Web.UI.UserControl {
I have a base user control (inherited from System.Web.UI.UserControl ) public delegate void MyEventHandler(object
I am using an ASP.Net Web Application project. I have a user control which
I have an custom control that extend System.Web.UI.UserControl. Is it possible to inherit user
I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static
I have a System.Web.Mvc.RazorView object which is strongly typed when in cshtml. Can I
I used mvc 4.0 to develop my web application, I have created a pager
I have a pretty complex class which extends System.Windows.Forms.UserControl . It's written in C++/CLI
I have abstract UserControlBase class inheriting from System.Web.UI.UserControl. It only class, without markup, because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.