Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » ASP.NET & Web Forms » Popup control in ASP.NET 2.0

Popup control in ASP.NET 2.0

In this article I am going to describe Popup control in ASP.NET 2.0.

Author Rank :
Page Views : 8741
Downloads : 365
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
PopupWithDiv.zip
 
 
Team Foundation Server Hosting
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Introduction:

 

In this article you will see how easy it is to use a simple DIV layer as a popup window that contained an ASP.NET Server control (List box). You will also see how on a mouse click inside a Textbox, you can able to popup a window which is nothing except a DIV Layer with some CSS formatting.

 

For Example:  Through this example you can learn how the popup controls create?

  

Html code for popup control:

 

<%@ Page language="c#" Inherits="PopupWithDiv.ParentPage" CodeFile="ParentPage.aspx.cs" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

<HEAD>

<title>Parent Page</title>

<LINK href="main.css" type="text/css" rel="stylesheet">

<script src="jsPopup.js" type="text/javascript"></script>

<script language="javascript">

<!--

          // Prevent users from typing any text

          // into the Textbox

          function ProtectBox(e)

          {

          return false;

          }

          -->

</script>

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<!-- Header Section -->

div id="header">

<p><font color= "#ff9933" size=6>Popup Window with DIV Layer</font></p>

</div>

<!-- Body Section -->

<div id="content">

<table border="0" cellpadding="0" cellspacing="0">

<tr valign="top">

<td><label for="txtCountry" style="font-size: larger; text-transform: capitalize; color: purple">Country :</label></td>

<td><asp:TextBox id="txtCountry" runat="server" OnKeyDown="return ProtectBox(event);" OnClick="PopupArea(event, 'divCountry')" BackColor="#FFC0FF" BorderColor="Fuchsia">Click here</asp:TextBox></td>

<td width="50"></td>

<td><label for="txtCity"style="font-size: larger; text-transform: capitalize; color: purple">City :</label></td>

<td><asp:TextBox id="txtCity" runat="server" OnKeyDown="return ProtectBox(event);" OnClick="PopupArea(event, 'divCity')" BackColor="#FFC0FF" BorderColor="Fuchsia">Click here</asp:TextBox></td>

</tr>

</table>

</div>

<%-- Country --%>

<div class="popupWindow" id="divCountry">

<table cellSpacing="0" cellPadding="0" width="250px" bgColor="#2557ad" border="0">

<tr>

<td align="right"><span style="CURSOR: hand" onclick="jsAreaClose('divCountry')"><img alt="Hide Popup" src="close.gif" border="0"></span></td>

</tr>

<tr>

<td>

<asp:ListBox id="lstCountry" runat="server" AutoPostBack="True" width="100%" rows="10" BackColor="rosybrown" ForeColor="gold" ></asp:ListBox></td>

</tr>

</table>

</div>

<%-- City --%>

<div class="popupWindow" id="divCity">

<table cellSpacing="0" cellPadding="0" bgColor="#2557ad" width="250px" border="0">

<tr>

<td align="right"><span style="CURSOR: hand" onclick="jsAreaClose('divCity')"><img alt="Hide Popup" src="close.gif" border="0"></span></td>

</tr>

<tr>

<td>

<asp:ListBox id="lstCity" runat="server" AutoPostBack="True" width="100%" rows="10" BackColor="RosyBrown" ForeColor="Gold"></asp:ListBox>

</td>

</tr>

</table>

</div>

</form>

</body>

</HTML>

 

 

Code behind code:

 

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

 

namespace PopupWithDiv

{

     /// <summary>

    /// Summary description for ParentPage.

    /// </summary>

    public partial class ParentPage : System.Web.UI.Page

    {     

        protected void Page_Load(object sender, System.EventArgs e)

        {

             // Load data into Country List box

             if (!Page.IsPostBack)

             {

                 // Load data from XML into a DataSet

                 DataSet ds = new DataSet();

                 ds.ReadXml(Server.MapPath("countries.xml"));

                 this.lstCountry.DataSource = ds.Tables[0].DefaultView;

                 this.lstCountry.DataTextField = "name";

                 this.lstCountry.DataBind();

            }

        }

 

             #region Web Form Designer generated code

             override protected void OnInit(EventArgs e)

             {

                 // CODEGEN: This call is required by the ASP.NET Web Form Designer.

                 InitializeComponent();

                 base.OnInit(e);

            }

            /// <summary>

            /// Required method for Designer support - do not modify

            /// the contents of this method with the code editor.

            /// </summary>

            private void InitializeComponent()

            {   

                this.lstCountry.SelectedIndexChanged +=new EventHandler(lstCountry_SelectedIndexChanged);

                this.lstCity.SelectedIndexChanged +=new EventHandler(lstCity_SelectedIndexChanged);

            }

            #endregion

            #region ListBox Event Handler

            private void lstCountry_SelectedIndexChanged(object sender, EventArgs e)

            {

                // Set the value in the textbox

                this.txtCountry.Text = this.lstCountry.SelectedValue;

                // Load and Filter the lstCity

                DataSet ds = new DataSet();

                ds.ReadXml(Server.MapPath("cities.xml"));

                DataView dv = ds.Tables[0].DefaultView;

                dv.RowFilter = "country = '" + this.lstCountry.SelectedValue + "'";

                / Bind lstCity

                this.lstCity.DataSource = dv;

                this.lstCity.DataTextField = "name";

                this.lstCity.DataBind();

           }

 

           private void lstCity_SelectedIndexChanged(object sender, EventArgs e)

           {

               // Set the value in the textbox

               this.txtCity.Text = this.lstCity.SelectedValue;

          }

           #endregion

     }      

}

 

Output: When you debug your application and click on the first textbox then you get the following output. It means the popup control opens.  

 

 

 

Figure 1: You are seeing the popup window in this figure.

 

This window will close automatically after some time or you can close it yourself.

When you select any country then you can select any city of that country from other popup window. If you will not select ant city then other popup window will open but you can not see the city in this example.

 

After select ant country you will see the following output.

 

 

 

Figure 2: second popup window is open.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Author
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Mindcracker MVP Summit 2012
Become a Sponsor
 Comments
Nevron Chart
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.