You do not have to have a CodeBehind, but the page will have to follow
certain rules. You can wire events either programatically or declaratively.
EXAMPLE 1: Programatic
-----------------------------
<%@ Page language="c#" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>UglyPage</title>
<script language="C#" runat="server">
// Page Load
private void Page_Load(object sender, System.EventArgs e)
{
}
override protected void OnInit(EventArgs e)
{
//Need an init to start the page
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.btnFill.Click += new System.EventHandler(this.btnFill_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
private void btnFill_Click(object sender, System.EventArgs e)
{
txtFill.Text = btnFill.Text;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h1>This is an ugly page</h1>
<P><asp:Button id=btnFill runat="server" Text="Click me to fill text
box"></asp:Button><asp:TextBox id=txtFill runat="server"></asp:TextBox></P>
</form>
</body>
</HTML>
EXAMPLE 2: Declarative
----------------------------
<%@ Page language="c#" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>UglyPage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="
http://schemas.microsoft.com/intellisense/ie5">
<script language="C#" runat="server">
private void btnFill_Click(object sender, System.EventArgs e)
{
txtFill.Text = btnFill.Text;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h1>This is an ugly page</h1>
<P><asp:Button id=btnFill runat="server" Text="Click me to fill text box"
OnClick="btnFill_Click"></asp:Button><asp:TextBox id=txtFill
runat="server"></asp:TextBox></P>
</form>
</body>
</HTML>
Wiring
OnClick="btnFill_Click" = declarative
this.btnFill.Click += new System.EventHandler(this.btnFill_Click); =
programatic
The src="" still uses a "CodeBehind" file, but it is dynamically compiled
when the page is hit rather than precompiled to IL when you deploy. Src=""
does not work in Visual Studio .NET, so do not use it if you are heading that
route.
---
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************