ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2017 www.aspforums.com. All rights reserved.How to log each User Controls load time using C# in ASP.Net<p><strong>Parent page</strong></p> <pre class="brush: html">&lt;%@ Page Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeBehind=&#34;StartStopParent.aspx.cs&#34; Inherits=&#34;TestingWeb.usercontrol.StartStopParent&#34; %&gt; &lt;%@ Register Src=&#34;~/usercontrol/StartEnd.ascx&#34; TagPrefix=&#34;uc1&#34; TagName=&#34;StartEnd&#34; %&gt;</pre> <p>&nbsp;</p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace TestingWeb.usercontrol { public partial class StartStopParent : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void StartEnd_Init(object sender, EventArgs e) { StartEnd.StartTime.Text = DateTime.Now.ToString(); Thread.Sleep(1000); } protected void StartEnd_PreRender(object sender, EventArgs e) { StartEnd.EndTime.Text = DateTime.Now.ToString(); } } }</pre> <p><strong>User Control</strong></p> <pre class="brush: html">&lt;%@ Control Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeBehind=&#34;StartEnd.ascx.cs&#34; Inherits=&#34;TestingWeb.usercontrol.StartEnd&#34; %&gt;</pre> <p>&nbsp;</p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace TestingWeb.usercontrol { public partial class StartEnd : System.Web.UI.UserControl { public Label StartTime { get { return Start; } } public Label EndTime { get { return End; } } protected void Page_Load(object sender, EventArgs e) { } } }</pre> <p>But the problem here is i need to create init and pre render even for each usercontrol. How do i avoid the code repetition here.how to make generic event handler and call that. Any sample please&nbsp;</p> <p>&nbsp;</p>http://www.aspforums.net/Threads/145619/How-to-log-each-User-Controls-load-time-using-C-in-ASPNet/http://www.aspforums.net/Threads/145619/How-to-log-each-User-Controls-load-time-using-C-in-ASPNet/Tue, 27 Dec 2016 22:37:11 GMTHow to log each User Controls load time using C# in ASP.Net<p>Hi <a class="username" rel="born2achie"> born2achie</a>,</p> <p>You can do it like below.</p> <p><span style="text-decoration: underline;">StartEnd.ascx </span></p> <pre class="brush: html">&lt;%@ Control Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;StartEnd.ascx.cs&#34; Inherits=&#34;StartEnd&#34; %&gt; &lt;asp:Label ID=&#34;Start&#34; runat=&#34;server&#34; /&gt; &lt;br /&gt; &lt;asp:Label ID=&#34;End&#34; runat=&#34;server&#34; /&gt;</pre> <p><span style="text-decoration: underline;">StartEnd1.ascx</span></p> <pre class="brush: html">&lt;%@ Control Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;StartEnd1.ascx.cs&#34; Inherits=&#34;StartEnd1&#34; %&gt; &lt;asp:Label ID=&#34;Start&#34; runat=&#34;server&#34; /&gt; &lt;br /&gt; &lt;asp:Label ID=&#34;End&#34; runat=&#34;server&#34; /&gt;</pre> <p><span style="text-decoration: underline;">StartEnd2.ascx </span></p> <pre class="brush: html">&lt;%@ Control Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;StartEnd2.ascx.cs&#34; Inherits=&#34;StartEnd2&#34; %&gt; &lt;asp:Label ID=&#34;Start&#34; runat=&#34;server&#34; /&gt; &lt;br /&gt; &lt;asp:Label ID=&#34;End&#34; runat=&#34;server&#34; /&gt;</pre> <p><span style="text-decoration: underline;">StartEnd3.ascx </span></p> <pre class="brush: html">&lt;%@ Control Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;StartEnd3.ascx.cs&#34; Inherits=&#34;StartEnd3&#34; %&gt; &lt;asp:Label ID=&#34;Start&#34; runat=&#34;server&#34; /&gt; &lt;br /&gt; &lt;asp:Label ID=&#34;End&#34; runat=&#34;server&#34; /&gt;</pre> <p><span style="text-decoration: underline;">StartEnd.ascx.cs</span></p> <p><span style="text-decoration: underline;">StartEnd1.ascx.cs</span></p> <p><span style="text-decoration: underline;">StartEnd2.ascx.cs</span></p> <p><span style="text-decoration: underline;">StartEnd3.ascx.cs </span></p> <pre class="brush: csharp">public Label StartTime { get { return Start; } } public Label EndTime { get { return End; } } protected void Page_Load(object sender, EventArgs e) { } </pre> <p><span style="text-decoration: underline;">StartStopParent.aspx</span></p> <pre class="brush: html">&lt;%@ Register Src=&#34;~/StartEnd.ascx&#34; TagPrefix=&#34;uc&#34; TagName=&#34;StartEnd&#34; %&gt; &lt;%@ Register Src=&#34;~/StartEnd1.ascx&#34; TagPrefix=&#34;uc1&#34; TagName=&#34;StartEnd1&#34; %&gt; &lt;%@ Register Src=&#34;~/StartEnd2.ascx&#34; TagPrefix=&#34;uc2&#34; TagName=&#34;StartEnd2&#34; %&gt; &lt;%@ Register Src=&#34;~/StartEnd3.ascx&#34; TagPrefix=&#34;uc3&#34; TagName=&#34;StartEnd3&#34; %&gt; &lt;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&gt; &lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;title&gt;&lt;/title&gt; &nbsp;&nbsp;&nbsp; &lt;style type=&#34;text/css&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; body &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-family: Arial; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-size: 10pt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border: 1px solid #ccc; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table th &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; background-color: #F7F7F7; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color: #333; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-weight: bold; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table th, table td &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; padding: 5px; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border-color: #ccc; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &nbsp;&nbsp;&nbsp; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;table border=&#34;1&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;uc:StartEnd ID=&#34;StartEnd&#34; runat=&#34;server&#34; OnInit=&#34;StartEnd_Init&#34; OnPreRender=&#34;StartEnd_PreRender&#34; /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;uc1:StartEnd1 ID=&#34;StartEnd1&#34; runat=&#34;server&#34; OnInit=&#34;StartEnd_Init&#34; OnPreRender=&#34;StartEnd_PreRender&#34; /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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nPreRender=&#34;StartEnd_PreRender&#34; /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/table&gt; &nbsp;&nbsp;&nbsp; &lt;/div&gt; &nbsp;&nbsp;&nbsp; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><span style="text-decoration: underline;">StartStopParent.aspx.cs</span></p> <pre class="brush: csharp">protected void StartEnd_Init(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; StartEnd.StartTime.Text = &#34;Start : &#34; + DateTime.Now.ToString(); &nbsp;&nbsp;&nbsp; Thread.Sleep(200); &nbsp;&nbsp;&nbsp; StartEnd1.StartTime.Text = &#34;Start1 : &#34; + DateTime.Now.ToString(); &nbsp;&nbsp;&nbsp; Thread.Sleep(200); &nbsp;&nbsp;&nbsp; StartEnd2.StartTime.Text = &#34;Start2 : &#34; + DateTime.Now.ToString(); &nbsp;&nbsp;&nbsp; Thread.Sleep(200); &nbsp;&nbsp;&nbsp; StartEnd3.StartTime.Text = &#34;Start3 : &#34; + DateTime.Now.ToString(); } protected void StartEnd_PreRender(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; StartEnd.EndTime.Text = &#34;End : &#34; + DateTime.Now.ToString(); &nbsp;&nbsp;&nbsp; Thread.Sleep(200); &nbsp;&nbsp;&nbsp; StartEnd1.EndTime.Text = &#34;End1 : &#34; + DateTime.Now.ToString(); &nbsp;&nbsp;&nbsp; Thread.Sleep(200); &nbsp;&nbsp;&nbsp; StartEnd2.EndTime.Text = &#34;End2 : &#34; + DateTime.Now.ToString(); &nbsp;&nbsp;&nbsp; Thread.Sleep(200); &nbsp;&nbsp;&nbsp; StartEnd3.EndTime.Text = &#34;End3 : &#34; + DateTime.Now.ToString(); }</pre> <p><span style="text-decoration: underline;">Output</span></p> <table border="1"> <tbody> <tr> <td><span id="StartEnd_Start">Start : 12/28/2016 9:17:00 PM</span> <span id="StartEnd_End">End : 12/28/2016 9:17:03 PM</span></td> </tr> <tr> <td><span id="StartEnd1_Start">Start1 : 12/28/2016 9:17:00 PM</span> <span id="StartEnd1_End">End1 : 12/28/2016 9:17:03 PM</span></td> </tr> <tr> <td><span id="StartEnd2_Start">Start2 : 12/28/2016 9:17:01 PM</span> <span id="StartEnd2_End">End2 : 12/28/2016 9:17:03 PM</span></td> </tr> <tr> <td><span id="StartEnd3_Start">Start3 : 12/28/2016 9:17:01 PM</span> <span id="StartEnd3_End">End3 : 12/28/2016 9:17:03 PM</span></td> </tr> </tbody> </table> <p>&nbsp;</p>http://www.aspforums.net/Threads/145619/How-to-log-each-User-Controls-load-time-using-C-in-ASPNet/http://www.aspforums.net/Threads/145619/How-to-log-each-User-Controls-load-time-using-C-in-ASPNet/Wed, 28 Dec 2016 08:42:28 GMTHow to log each User Controls load time using C# in ASP.Net<p>thank you dharmendr and&nbsp;sorry for the late reply as i was on vacation. thank you and i will try and get back</p>http://www.aspforums.net/Threads/145619/How-to-log-each-User-Controls-load-time-using-C-in-ASPNet/http://www.aspforums.net/Threads/145619/How-to-log-each-User-Controls-load-time-using-C-in-ASPNet/Tue, 10 Jan 2017 18:34:16 GMT