Tuesday, November 30, 2010

ASP Example

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Calendar ID="Calendar1" runat="server"
onselectionchanged="Calendar1_SelectionChanged">
<DayHeaderStyle CssClass="testClass" />
</asp:Calendar>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

</div>
</form>
</body>
</html>

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> myList= new List<string>();

myList.Add("One");
myList.Add("Two");
myList.Add("Three");
myList.Add("Four");

DropDownList1.DataSource = myList;
DropDownList1.DataBind();

Label1.Text = myList[2].ToString();


}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{

Label1.Text = Calendar1.SelectedDate.ToShortDateString();

if (Calendar1.SelectedDate.ToShortDateString() == "12/25/2010")
{
Label1.CssClass = "testClass";
Label1.Text = "Merry Christmas!";
}
else
{
Label1.CssClass = "";

}

// Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Hello this is an Alert')</SCRIPT>");

}
}

Stylessheet.cssbody
{
font-family:Verdana, Sans-Serif;
font-size:larger;
}
h1
{
font-size:150%;
color:Navy;
}

.testClass
{
color:Red;
}

No comments:

Post a Comment