Frage

I swear to god I tried googling it. I have a webcontrol that logs into the database the time and date of a page load, and same of page unload.

I can't set it up to save my life.

can somebody provide a solution?

Thanks!

War es hilfreich?

Lösung

You can use UserControl's Load and Unload events.

public partial class WebUserControl1 : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Log to Database
    }

    protected void Page_Unload(object sender, EventArgs e)
    {
        // Log to Database
    }
}

Here is ASP.Net Page Life Cycle

enter image description here

Andere Tipps

The page fires the load event, which recursively goes through all of its controls, including your user control, to fire that load event on it. same action occurs for Unload. The page controls it all, which is controlled by the module that controls the ASP.NET framework.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top