First Page
Design Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="0">--SELECT--</asp:ListItem>
<asp:ListItem Value="1">Kolkata</asp:ListItem>
<asp:ListItem Value="2">Bengaluru</asp:ListItem>
<asp:ListItem Value="3">Mumbai</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Next Page" />
</div>
</form>
</body>
</html>
Code File
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(DropDownList1.SelectedValue.Trim()) > 0)
{
if (Convert.ToInt32(DropDownList1.SelectedValue.Trim()) == 1)
{
Session["City"] = DropDownList1.SelectedItem.ToString();
Response.Redirect("nextPage.aspx");
}
else if (Convert.ToInt32(DropDownList1.SelectedValue.Trim()) == 2)
{
Session["City"] = DropDownList1.SelectedItem.ToString();
Response.Redirect("nextPage.aspx");
}
else if (Convert.ToInt32(DropDownList1.SelectedValue.Trim()) == 3)
{
Session["City"] = DropDownList1.SelectedItem.ToString();
Response.Redirect("nextPage.aspx");
}
}
else
{
Response.Write("<script>alert('Please Select City');</script>");
}
}
}
Next Page Code File
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class nextPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["City"].ToString() != string.Empty)
{
Response.Write("It Is "+ Session["City"].ToString());
}
}
}
Screenshot