Skip to content

Instantly share code, notes, and snippets.

@greybax
Last active August 29, 2015 14:01
Show Gist options
  • Save greybax/d4147fb046cf9b3cf7d3 to your computer and use it in GitHub Desktop.
Save greybax/d4147fb046cf9b3cf7d3 to your computer and use it in GitHub Desktop.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Asp.net_sample_events.aspx.cs" Inherits="AspNetSampleEvents._Default" %>
<asp:TextBox runat="server" ID="textBox" Text="Sample text"> </asp:TextBox>
<asp:Button runat="server" ID="button" Text="Click me"> </asp:Button>
</asp:Content>
using System;
using System.Diagnostics;
using System.Web.UI;
namespace AspNetSampleEvents
{
public partial class _Default : Page
{
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
Debug.WriteLine("OnPreInit");
LogEvent("OnPreInit");
}
protected override void OnInit(EventArgs e)
{
base.OnPreInit(e);
Debug.WriteLine("OnInit");
LogEvent("OnInit");
}
protected override void OnPreLoad(EventArgs e)
{
base.OnPreLoad(e);
Debug.WriteLine("OnPreLoad");
LogEvent("OnPreLoad");
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
Debug.WriteLine("OnPreRender");
LogEvent("OnPreRender");
}
protected override void OnUnload(EventArgs e)
{
base.OnUnload(e);
Debug.WriteLine("OnUnload");
LogEvent("OnUnload");
}
private void LogEvent(string eventName)
{
Debug.WriteLine("IsPostBack = " + IsPostBack);
Debug.WriteLine("IsTrackingViewState = " + IsTrackingViewState);
if (textBox == null)
Debug.WriteLine("textBox = null");
else
{
Debug.WriteLine("textBox.Text = " + textBox.Text);
textBox.Text += " " + eventName + " ";
Debug.WriteLine("textBox.Text = " + textBox.Text);
}
var responseText = "Response.Write " + eventName;
try
{
Response.Write(responseText);
}
catch (Exception)
{
Debug.WriteLine("Error: " + responseText);
}
finally
{
Debug.WriteLine(responseText);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment