How to log each User Controls load time using C# in ASP.Net

Last Reply 6 days ago By born2achie

Posted 21 days ago

Hi,

I have 6 users controls in my page and i want to log the each user controls load time in backend. Any suggestion how to achieve this? 

Posted 19 days ago Modified on 19 days ago

Hi born2achie,

You can do it like below.

StartEnd.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="StartEnd.ascx.cs" Inherits="StartEnd" %>
<asp:Label ID="Start" runat="server" />
<br />
<asp:Label ID="End" runat="server" />

StartEnd1.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="StartEnd1.ascx.cs" Inherits="StartEnd1" %>
<asp:Label ID="Start" runat="server" />
<br />
<asp:Label ID="End" runat="server" />

StartEnd2.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="StartEnd2.ascx.cs" Inherits="StartEnd2" %>
<asp:Label ID="Start" runat="server" />
<br />
<asp:Label ID="End" runat="server" />

StartEnd3.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="StartEnd3.ascx.cs" Inherits="StartEnd3" %>
<asp:Label ID="Start" runat="server" />
<br />
<asp:Label ID="End" runat="server" />

StartEnd.ascx.cs

StartEnd1.ascx.cs

StartEnd2.ascx.cs

StartEnd3.ascx.cs

public Label StartTime
{
    get { return Start; }
}
public Label EndTime
{
    get { return End; }
}

protected void Page_Load(object sender, EventArgs e)
{

}  

StartStopParent.aspx

<%@ Register Src="~/StartEnd.ascx" TagPrefix="uc" TagName="StartEnd" %>
<%@ Register Src="~/StartEnd1.ascx" TagPrefix="uc1" TagName="StartEnd1" %>
<%@ Register Src="~/StartEnd2.ascx" TagPrefix="uc2" TagName="StartEnd2" %>
<%@ Register Src="~/StartEnd3.ascx" TagPrefix="uc3" TagName="StartEnd3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
        table
        {
            border: 1px solid #ccc;
        }
        table th
        {
            background-color: #F7F7F7;
            color: #333;
            font-weight: bold;
        }
        table th, table td
        {
            padding: 5px;
            border-color: #ccc;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table border="1">
            <tr>
                <td>
                    <uc:StartEnd ID="StartEnd" runat="server" OnInit="StartEnd_Init" OnPreRender="StartEnd_PreRender" />
                </td>
            </tr>
            <tr>
                <td>
                    <uc1:StartEnd1 ID="StartEnd1" runat="server" OnInit="StartEnd_Init" OnPreRender="StartEnd_PreRender" />
                </td>
            </tr>
            <tr>
                <td>
                    <uc2:StartEnd2 ID="StartEnd2" runat="server" OnInit="StartEnd_Init" OnPreRender="StartEnd_PreRender" />
                </td>
            </tr>
            <tr>
                <td>
                    <uc3:StartEnd3 ID="StartEnd3" runat="server" OnInit="StartEnd_Init" OnPreRender="StartEnd_PreRender" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

StartStopParent.aspx.cs

protected void StartEnd_Init(object sender, EventArgs e)
{
    StartEnd.StartTime.Text = "Start : " + DateTime.Now.ToString();
    Thread.Sleep(200);
    StartEnd1.StartTime.Text = "Start1 : " + DateTime.Now.ToString();
    Thread.Sleep(200);
    StartEnd2.StartTime.Text = "Start2 : " + DateTime.Now.ToString();
    Thread.Sleep(200);
    StartEnd3.StartTime.Text = "Start3 : " + DateTime.Now.ToString();
}

protected void StartEnd_PreRender(object sender, EventArgs e)
{
    StartEnd.EndTime.Text = "End : " + DateTime.Now.ToString();
    Thread.Sleep(200);
    StartEnd1.EndTime.Text = "End1 : " + DateTime.Now.ToString();
    Thread.Sleep(200);
    StartEnd2.EndTime.Text = "End2 : " + DateTime.Now.ToString();
    Thread.Sleep(200);
    StartEnd3.EndTime.Text = "End3 : " + DateTime.Now.ToString();
}

Output

Start : 12/28/2016 9:17:00 PM End : 12/28/2016 9:17:03 PM
Start1 : 12/28/2016 9:17:00 PM End1 : 12/28/2016 9:17:03 PM
Start2 : 12/28/2016 9:17:01 PM End2 : 12/28/2016 9:17:03 PM
Start3 : 12/28/2016 9:17:01 PM End3 : 12/28/2016 9:17:03 PM

 

I agree, here is the link: http://e-iceblue.com/free-api