Thursday, January 5, 2012

Stuf for the first Assignment

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

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Stuff</h1>
    <asp:DropDownList ID="DropDownList1" runat="server">
        
        </asp:DropDownList>
        <p><asp:Label ID="Label1" runat="server" Text="Enter Name"></asp:Label>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox></p>
        <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
        
    
        <asp:Button ID="btnConfirm" runat="server" Text="Confirm" 
            onclick="btnConfirm_Click" />
        
    
    </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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string[] colors = new string[5];
        colors[0] = "Blue";
        colors[1] = "Green";
        colors[2] = "Red";
        colors[3] = "Yellow";
        colors[4] = "Teal";

        if (!IsPostBack)
        {
            DropDownList1.DataSource = colors;
            DropDownList1.DataBind();
        }

        //DropDownList1.Items.Add("Red");
        //DropDownList1.Items.Add("Green");
    }
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        string name = txtName.Text;
        string date = Calendar1.SelectedDate.ToShortDateString();
        string chosenColor = DropDownList1.SelectedItem.ToString();

        //Response.Redirect("Confirmation.aspx?name=" 
        //    + name+"&date="
        //    +date+"&color="+chosenColor);

        Session["name"] = name;
        Session["color"]=chosenColor;
        Session["date"] = date;

        Response.Redirect("Confirmation.aspx");
    }
   
}

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

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Confirmation Page</h1>
    </div>
    <asp:Label ID="lblName" runat="server" Text="Label"></asp:Label><br />
    <asp:Label ID="lblColor" runat="server" Text="Label"></asp:Label><br />
    <asp:Label ID="lblDate" runat="server" Text="Label"></asp:Label>


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


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

public partial class Confirmation : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //lblColor.Text = Request.QueryString["color"];
        //lblName.Text = Request.QueryString["name"];
        //lblDate.Text = Request.QueryString["date"];
        if (Session["color"] != null)
        {
            lblColor.Text = Session["color"].ToString();
            lblDate.Text = Session["date"].ToString();
            lblName.Text = Session["name"].ToString();
        }
        else
        {
            Response.Redirect("Default.aspx");
        }

        
    }
}

No comments:

Post a Comment