void Page_PreRender()
{
string upFolder = MapPath("~/UploadImages/");
DirectoryInfo dir = new DirectoryInfo(upFolder);
dlstImages.DataSource = dir.GetFiles();
dlstImages.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>FileUpload File</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label
id="lblImageFile"
Text="Image File:"
AssociatedControlID="upImage"
Runat="server" />
<asp:FileUpload
id="upImage"
Runat="server" />
<asp:Button
id="btnAdd"
Text="Add Image"
OnClick="btnAdd_Click"
Runat="server" />
<hr />
<asp:DataList
id="dlstImages"
RepeatColumns="3"
runat="server">
<ItemTemplate>
<asp:Image ID="Image1"
ImageUrl='<%# Eval("Name", "~/UploadImages/{0}") %>'
style="width:200px"
Runat="server" />
<br />
<%# Eval("Name") %>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
}
}
else
{
labMessage.Text = "File was not specified";
}
}
catch
{
labMessage.Text = "File was not uploaded";
}
}
}
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
try
{
Uploader.PostedFile.SaveAs(fullUploadPath);
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
try {
FileUpload1.SaveAs("C:\\Uploads\\" + FileUpload1.FileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex) {
Label1.Text = "ERROR: " + ex.Message.ToString();
}
else
{
Label1.Text = "You have not specified a file.";
}
}
</script>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("C:\Uploads\" & _
FileUpload1.FileName)
Label1.Text = "File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength & " kb<br>" & _
"Content type: " & _
FileUpload1.PostedFile.ContentType
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub
</script>
<httpRuntime
idleTime="15"
executionTimeout="90"
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="False"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>
The user selects a file from the local disk and the page manages to persist it to a server
location
<%@ Page language="C#"%>
<%@ Import Namespace="System.IO" %>
<script runat="server">
void UploadButton_Click(object sender, EventArgs e)
{
string savePath = UploadPath.Text.ToLower();
if (!Directory.Exists(savePath))
{
Response.Write(String.Format("<h1>The upload path doesn't exist: {0}</h1>",
savePath));
Response.End();
}
if (FileUpload1.HasFile)
{
string fileName = FileUpload1.FileName;
savePath += fileName;
FileUpload1.SaveAs(savePath);
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>File Upload</title>
</head>
<body>
<div id="pageContent">
<form id="Form1" runat="server">
<h4>Select a picture to upload:</h4>
<b>Upload Path</b><br />
<asp:textbox id="UploadPath" runat="server" text="c:\temp\pictures\" />
<hr />
<b>Picture to upload</b><br />
<asp:fileupload id="FileUpload1" runat="server" />
<br /><br />
<asp:button id="UploadButton"
text="Upload"
onclick="UploadButton_Click"
runat="server">
</asp:button>
<hr />
void Page_Load()
{
lblServerTime.Text = DateTime.Now.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>First Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label
id="lblServerTime"
Runat="server" />
</div>
</form>
</body>
</html>
The code declaration block contains all the methods used in the page.
It contains all the page's functions and subroutines.
<script runat="server">
void Page_Load()
{
lblServerTime.Text = DateTime.Now.ToString();
}
</script>
1. 1. 2. The ASP.NET Framework gives you the most commonly used namespaces
System
System.Collections
System.Collections.Specialized
System.Configuration
System.Text
System.Text.RegularExpressions
System.Web
System.Web.Caching
System.Web.SessionState
System.Web.Security
System.Web.Profile
System.Web.UI
System.Web.UI.WebControls
System.Web.UI.WebControls.WebParts
System.Web.UI.HTMLControls
System.Web.Extensions
System.Xml.Linq
System.Data.DataSetExtensions
The default namespaces are listed inside the pages element in the root web configuration
file
located at the following path:
\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Web.Config
mscorlib.dll
System.dll
System.Configuration.dll
System.Web.dll
System.Data.dll
System.Web.Services.dll
System.Xml.dll
System.Drawing.dll
System.EnterpriseServices.dll
System.Web.Mobile.dll
App_Browsers Contains browser definition files (which are XMLbased files with the
.browser extension) used by this application for
identifying and determining the capabilities of browsers.
App_Data Contains application data files, such as SQL Server Express data, Microsoft
Access files, or XML data.
App_LocalResources Contains resource files that are associated with a specific page or
control.
App_Themes Contains files that define the appearance of pages and controls in the site.
Extension Description
.ascx Defines a user control. User controls are used to encapsulate a block of reusable
user interface functionality.
.ashx Defines a custom HTTP handler. Handlers are used to implement custom
response functionality based on the extension of the request.
.master Defines a master page that specifies the common layout for other Web Forms.
.skin Defines the visual property settings to be applied to controls in a site's theme.
App_Code Contains source code files that are dynamically compiled for use
\App_Code Folder stores your classes, .wsdl files, and typed datasets.
Items in this folder are automatically available to all the pages within your solution.
Because all the classes contained in this folder are built into a single assembly,
you cannot have classes of different languages sitting in the root \App_Code folder
\App_Code
Calculator.cs
AdvancedMath.vb
The first step is to add two new subfolders to the \App_Code folder - a \VB folder and
a \CS folder.
\App_Code
\VB
Add.vb
\CS
Subtract.cs
You can control the behavior of your ASP.NET pages by using these directives.
Directives are commands that the compiler uses when the page is compiled.
You can add more than a single attribute to your directive statements:
1. 2. 4. directives in ASP.NET
Directive Description
Assembly Links an assembly to the Page or user control for which it is associated.
Control For using with user controls (.ascx).
Implements Implements a specified .NET Framework interface.
Import Imports namespaces into the Page or user control.
Master Set master page. It be used only with master pages (.master).
MasterType Associates a class name to a Page in order to get at strongly typed
references.
OutputCache Controls the output caching policies of a Page or user control.
Page Enables you to specify page specific attributes and values to use when the
page parses or compiles.
PreviousPageType Enables an ASP.NET page to work with a postback from another
page in the application.
Reference Links a Page or user control to the current Page or user control.
Register Associates aliases with namespaces and class names for notation in
custom server control syntax.
1. 2. 5. @Page directive
@Page directive sets attributes and values for an ASP.NET page (.aspx).
1. 3. 1. code-inline model: all the code is contained within a single .aspx page
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = "Hello " + Textbox1.Text;
}
</script>
1. 3. 2. code-behind model allows for code separation of the page's business logic from
its presentation logic
presentation logic for the page is stored in an .aspx page, whereas the logic piece is stored
in a separate class file: .aspx.vb or .aspx.cs.
An .aspx page that uses the ASP.NET 2.0 code-behind model (VB version)
An .aspx page that uses the ASP.NET 2.0 code-behind model (C# version)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
<asp:Button
id="Button1"
Text="Click Here"
OnClick="Button1_Click"
Runat="server" />
<asp:Label
id="Label1"
Runat="server" />
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
<asp:Button
id="Button1"
Text="Click Here"
Runat="server" />
<asp:Label
id="Label1"
Runat="server" />
</div>
</form>
</body>
</html>
File: Default.aspx.vb
1. 4. 1. Expression
The global application class that's used by the global.asax file should always be stateless.
<script runat="server">
</script>
</script>
1. 6. 5. Global.asax file can be used to track the number of page requests made for any
page.
File: Global.asax
<script runat="server">
</script>
File: Global.asax
File: Default.aspx
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using ASP;
<script runat="server">
</script>
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
namespace MyApp
{
public class Global : System.Web.HttpApplication
{
protected void Application_Error(Object sender, EventArgs e)
{
System.Diagnostics.EventLog myEventLog;
Exception ex=Server.GetLastError();
myEventLog=new System.Diagnostics.EventLog();
myEventLog.Log="Application";
myEventLog.Source="Default";
myEventLog.WriteEntry(ex.ToString());
myEventLog=null;
}
}
}
1. 6. 11. Log exception in Global.asax (VB)
Imports System.Web
Imports System.Web.SessionState
File: Default.aspx
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
}
protected void cmd_Click(object sender, EventArgs e)
{
Response.Redirect("NextPage.aspx" + "?Version=" +
((Control)sender).ID);
}
}
File: NextPage.aspx
File: NextPage.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim strClockStatus As String
strClockStatus = "AAA"
<html><body>
</body></html>
<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim intAge As integer = 7
end sub
</script>
<html><body>
</body></html>
<script runat="server">
Sub Button_Click(Sender As Object, e As EventArgs)
Response.Write(Sender.Text)
End Sub
</script>
<html>
<body>
<form runat="server">
<asp:button id="btSubmit" Text="Submit" runat=server OnClick="Button_Click"/>
</form>
</body>
</html>
<script runat="server">
Sub Button1_Click(Sender as Object, e as EventArgs)
Label1.Text="You clicked <b>" & Sender.Text & "</b>"
end Sub
</script>
<html><body>
<form runat="server">
<asp:Button id=Button1 runat="server" Text="Button1"
onClick="Button1_Click" />
<script runat="server">
void Button1_Click(Object Sender, EventArgs e) {
Label1.Text = "You clicked <b>" + ((Button)Sender).Text + "</b>";
}
</script>
<html><body>
<form runat="server">
<asp:Button id=Button1 runat="server" Text="Button1"
onClick="Button1_Click" />
<script runat="server">
Sub Click(Sender as Object, e as EventArgs)
select case Sender.Value
case "Left"
word_image.align = "left"
case "Right"
word_image.align = "right"
case "Center"
word_image.align = "center"
end select
Left.Style("Border-Style") = "notset"
Right.Style("Border-Style") = "notset"
Center.Style("Border-Style") = "notset"
Sender.Style("Border-Style") = "inset"
end Sub
</script>
<html><body>
<form runat="server">
<input type="Button" id="Left" runat="server"
Value="Left" OnServerClick="Click" />
<input type="Button" id="Center" runat="server"
Value="Center" OnServerClick="Click" />
<input type="Button" id="Right" runat="server"
Value="Right" OnServerClick="Click" />
</form>
<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim strDay as string
dim arrWeekDays() as String = {"Monday", "Tuesday", _
"Wednesday", "Thursday", "Friday"}
end sub
</script>
<html><body>
</body></html>
2. 4. 1. Define and call function in asp.net page (C#)
<script runat="server">
void Page_Load(Object Sender, EventArgs e) {
MultiplyNumbers(8,9);
MultiplyNumbers(4,12);
MultiplyNumbers(38,23);
}
<html><body>
</body></html>
<script runat="server">
sub Page_Load(obj as object,e as eventargs)
Response.Write(MultiplyNumbers(8,9)&"<br>")
Response.Write(MultiplyNumbers(4,12)&"<br>")
Response.Write(MultiplyNumbers(38,23)&"<br>")
end sub
</body></html>
2. 4. 3. Define function
string getName()
{
return "Abc";
}
void Page_Load()
{
messageLabel.Text = getName();
}
</script>
</head>
<body>
<form runat="server">
<asp:Label id="messageLabel" runat="server" />
</form>
</body>
</html>
<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim MyMessage As String = "Hello"
dim MyBool As Boolean = True
if MyBool then
Response.Write("True")
end if
end sub
</script>
<html><body>
</body></html>
<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim MyMessage As String = "Hello"
dim MyBool As Boolean = True
if MyBool then
Response.Write("True")
end if
end sub
</script>
<html><body>
</body></html>
2. 5. 3. Use if and 'if else' statement with string and boolean type value (C#)
<script runat="server">
void Page_Load(Object Sender, EventArgs e) {
string MyMessage = "Hello";
bool MyBool = true;
if (!MyBool) {
Response.Write("False");
}
}
</script>
<html><body>
</body></html>
<script runat="server">
sub Page_Load(Sender as object,e as EventArgs)
MultiplyNumbers(8,9)
MultiplyNumbers(4,12)
MultiplyNumbers(38,23)
end sub
<html><body>
</body></html>
File: Default.aspx.vb
DisplayMessage()
End Sub
File: Default.aspx.vb
End Class
2. 7. 1. While loop
messageLabel.Text = counter.ToString();
counter++;
}
}
</script>
</head>
<body>
<form runat="server">
<asp:Label id="messageLabel" runat="server"/>
</form>
</body>
</html>
2. 7. 2. Do while loop
int counter = 0;
do
{
messageLabel.Text = counter.ToString();
counter++;
}
while (counter <= 10);
}
</script>
</head>
<body>
<form runat="server">
<asp:Label id="messageLabel" runat="server"/>
</form>
</body>
</html>
messageLabel.Text = counter.ToString()
counter += 1
Loop
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:Label id="messageLabel" runat="server" />
</form>
</body>
</html>
Do
messageLabel.Text = counter.ToString()
counter += 1
Loop While counter <= 10
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:Label id="messageLabel" runat="server" />
</form>
</body>
</html>
void Page_Load()
{
lblTime.Text = DateTime.Now.ToString("T");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show Label</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label
id="lblTime"
Runat="server" />
</div>
</form>
</body>
</html>
<script runat="server">
sub Page_Load(obj as object, e as eventargs)
lblMessage.Text = "This is my first exercise!"
end sub
</script>
<html><body>
<asp:Label id="lblMessage" runat="server"/>
</body></html>
<script runat="server">
sub Page_Load(obj as object, e as eventargs)
lblMessage.Text = "This is my first exercise!"
end sub
</script>
<html><body>
<asp:Label id="lblMessage" runat="server"/>
</body></html>
.heading1
{
font-weight: bold;
font-size: large;
color: lime;
}
.heading2
{
font-weight: bold;
font-size: medium;
font-style: italic;
color: #C0BA72;
}
.blockText
{
padding: 10px;
background-color: #FFFFD9;
border-style: solid;
border-width: thin;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label CssClass="heading1" ID="Label1" runat="server" Text="This Label
Uses heading1"></asp:Label>
<br />
This is sample unformatted text.<br />
<br />
<asp:Label CssClass="heading2" ID="Label2" runat="server" Text="This Label
Uses heading2"></asp:Label>
<br />
Here's more unformatted text.<br />
<br />
<div class="blockText" id="DIV1" runat="server" >
This control uses the blockText style. This control uses the blockText style. This
control uses the blockText style. This control uses the blockText style.
</div>
</div>
</form>
</body>
</html>
3. 1. 5. Label font
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
<script runat="server">
sub Page_Load(obj as object, e as eventargs)
lblMessage.Text = "Welcome to ASP.NET!"
end sub
</script>
<html>
<body>
<asp:Label id="lblMessage" runat="server"/>
</body>
</html>
Page Language='C#'
<script runat="server">
void Page_Load(Object obj, EventArgs e) {
lblMessage.Text = "Welcome to ASP.NET!";
}
</script>
<html><body>
<asp:Label id="lblMessage" runat="server"/>
</body></html>
<asp:Label
id="lblFirst"
Text="First Label"
ForeColor="Red"
BackColor="Yellow"
BorderStyle="Solid"
BorderWidth="2"
BorderColor="red"
Runat="server" />
<br />
<asp:Label
id="lblSecond"
Text="Second Label"
CssClass="labelStyle"
Runat="server" />
</div>
</form>
</body>
</html>
<asp:Label
id="lblFirstName"
Text="First Name:"
AssociatedControlID="txtFirstName"
Runat="server" />
<br />
<asp:TextBox
id="txtFirstName"
Runat="server" />
<asp:Label
id="lblLastName"
Text="Last Name:"
AssociatedControlID="txtLastName"
Runat="server" />
<br />
<asp:TextBox
id="txtLastName"
Runat="server" />
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Label For</title>
</head>
<body>
<div id="pageContent">
<form runat="server" id="MainForm">
<asp:Label ID="Label1" runat="server" Text="This label has no associated
control"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" />
<br />
<asp:Label ID="Label2" runat="server" Text="This label is associated with the
textbox"
AssociatedControlID="TextBox2"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" />
</form>
</div>
</body>
</html>
3. 2. 1. asp:Literal
3. 2. 2. Literal Control
The Literal control is similar to the Label control.
However, unlike the Label control, the Literal control does not render its content inside of
a <span> tag.
</div>
</form>
</body>
</html>
Encode: Displays the contents of the control after HTML encoding the content.
Transform: Displays the contents of the control after stripping markup that is not
supported by the requesting device.
<asp:Literal
id="ltlFirst"
Mode="PassThrough"
Text="<hr />"
Runat="server" />
<asp:Literal
id="ltlSecond"
Mode="Encode"
Text="<hr />"
Runat="server" />
<asp:Literal
id="ltlThird"
Mode="Transform"
Text="<hr />"
Runat="server" />
</div>
</form>
</body>
</html>
File: Default.aspx.vb
OnClientClick: specify a client-side script that executes when the button is clicked.
<script runat="server">
Sub tbMessage_Change(Sender As Object,E As EventArgs)
lblMessage.Text = "Hello" + tbMessage.Text
End Sub
</script>
<html>
<body>
<%Response.Write("Our First Page")%>
<form runat="server">
Please enter your name:
<asp:textbox id="tbMessage" OnTextChanged="tbMessage_Change"
runat=server/>
<asp:button id="btSubmit" Text="Submit" runat=server/>
<asp:label id="lblMessage" font-size="20pt" runat=server/>
</form>
</body>
</html>
<script runat="server">
Sub btAdd_Click(Sender As Object, E As EventArgs)
lblMessage.Text = "The answer is: " & Cint(tbNumber1.Text) +
Cint(tbNumber2.Text)
End Sub
<HTML>
<HEAD>
</HEAD>
<BODY>
<form runat="server">
</form>
</BODY>
</HTML>
<script runat="server">
void btAdd_Click(Object Sender, EventArgs e) {
lblMessage.Text = "The answer is: " + (Convert.ToInt32(tbNumber1.Text) +
Convert.ToInt32(tbNumber2.Text)).ToString();
}
void btSubtract_Click(Object Sender, EventArgs e) {
lblMessage.Text = "The answer is: " + (Convert.ToInt32(tbNumber1.Text) -
Convert.ToInt32(tbNumber2.Text)).ToString();
}
<HTML>
<HEAD>
</HEAD>
<BODY>
<form runat="server">
</form>
</BODY>
</HTML>
File: test.aspx.vb
End Sub
End Class
First Counter:
<asp:Button
id="Button1"
Text="0"
OnClick="Button_Click"
Runat="server" />
Second Counter:
<asp:Button
id="Button2"
Text="0"
OnClick="Button_Click"
Runat="server" />
</div>
</form>
</body>
</html>
<asp:ImageButton
id="btnElephant"
ImageUrl="http://www.java2s.com/style/logo.png"
OnClick="btnElephant_Click"
Runat="server" />
<br />
X Coordinate:
<asp:Label
id="lblX"
Runat="server" />
<br />
Y Coordinate:
<asp:Label
id="lblY"
Runat="server" />
</div>
</form>
</body>
</html>
3. 3. 8. Hide a controll
</head>
<body>
<form id="form1" runat="server">
<div id="container">
<h1>Check Box Test</h1>
<div class="box">
Delivery:
<asp:CheckBox ID="chkDelivery" runat="server"
OnCheckedChanged="CheckChanged" AutoPostBack="True" />
<asp:Label ID="labAddress"
runat="server"
Text="Customer Address: "
Visible="false" /><br />
<asp:TextBox ID="txtAddress"
runat="server"
Columns="60"
Visible="False" />
Pizza Styles: <br />
<asp:CheckBox ID="chkThin" runat="server" Text="Thin Crust" />
<br />
<asp:CheckBox ID="chkExtra" runat="server" Text="Extra Sauce" />
</div>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
<asp:Button
id="btnDelete"
Text="Delete Website"
OnClick="btnDelete_Click"
OnClientClick="return confirm('Are you sure?');"
Runat="server" />
<asp:Label
id="lblResult"
Runat="server" />
</div>
</form>
</body>
</html>
<script runat="server">
void Page_Load (object sender, System.EventArgs e) {
string text = "Yeah, you clicked the button!";
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<asp:button id="Button1" runat="server" text="Button" />
<br />
<br />
<asp:label id="Label1" runat="server">Please click da button!</asp:label>
</form>
</body>
</html>
<script runat="server">
void Page_Load (object sender, System.EventArgs e) {
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<asp:button id="Button1" runat="server" text="Button" />
<br />
<br />
<asp:label id="Label1" runat="server">click button!</asp:label>
</form>
</body>
</html>