Sunday, 28 September 2014

How to use the combination of Two DropDownList With AJAX Extensions(ScriptManager & Timer).


Objective:-Write a Programme to use the combination of Two DropDownList With AJAX Extensions(ScriptManager & Timer) And Wait gif Animation Image.

STEPS :-
STEP:- 1  CREATE NEW PROJECT.
Go to File -> New -> Project -> Select asp.net web forms application -> Entry Application Name -> Click OK.

STEP:- 2  ADD TOOLS
Drag & Drop these tools which you can see in the Left side of toolbox.
I think this image will help you that which tool you have to Drag & Drop from Toolbox.



STEP:- 3 To Create a folder and keep a image in the folder.
Go to Solution Explorer-> Right clock on WebApplication-> Add-> Click on New Folder
Rename and paste Any Wait gif Animation Image from given link.
http://softbehave.blogspot.in/p/collection-of-loading-image.html



********HTML Code***************

  1. <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
  2.     CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

  3. <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
  4. </asp:Content>
  5. <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  6.     <h2>
  7.         Welcome to ASP.NET!
  8.     </h2>
  9.     <div style="height: 300px">
  10.     <br/>
  11.     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  12.         <asp:Image ID="Image1" runat="server" ImageUrl="~/Image/SmallLoader.gif" />
  13.         <br />
  14. &nbsp; Enter Catogary:&nbsp;
  15.         <asp:DropDownList ID="DropDownList1" runat="server">
  16.             <asp:ListItem>Boy</asp:ListItem>
  17.             <asp:ListItem>Girl</asp:ListItem>
  18.             <asp:ListItem>Animal</asp:ListItem>
  19.         </asp:DropDownList>
  20. &nbsp;
  21.         <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Small" 
  22.             ForeColor="Blue" Text="Please Wait . . ."></asp:Label>
  23.         <br />
  24. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  25.         <br />
  26. &nbsp;&nbsp;&nbsp; Sub Catogary:&nbsp;
  27.         <asp:DropDownList ID="DropDownList2" runat="server">
  28.         </asp:DropDownList>
  29.         <br />
  30.         <br />
  31. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  32.         <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Show" />
  33. &nbsp;&nbsp;
  34.         <br />
  35. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  36.         <br />
  37. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  38.         <br />
  39.         <asp:ScriptManager ID="ScriptManager1" runat="server">
  40.         </asp:ScriptManager>
  41. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  42.         <asp:Timer ID="Timer1" runat="server" Enabled="False" Interval="6000" 
  43.             ontick="Timer1_Tick">
  44.         </asp:Timer>
  45.     </div>
  46. </asp:Content>




********C# Code***************

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;

  7. namespace WebApplication1
  8. {
  9.     public partial class _Default : System.Web.UI.Page
  10.     {
  11.         int sec = 0;
  12.         protected void Page_Load(object sender, EventArgs e)
  13.         {
  14.             Image1.Visible = false;
  15.             Label1.Visible = false;
  16.         }

  17.         protected void Timer1_Tick(object sender, EventArgs e)
  18.         {
  19.             sec++;
  20.             if (sec == 10)
  21.             {
  22.                                
  23.             }
  24.             Image1.Visible = false;
  25.             Timer1.Enabled = false;
  26.             Label1.Visible = false;
  27.             if (DropDownList1.Text == "Boy")
  28.             {
  29.                 DropDownList2.Items.Clear();
  30.                 DropDownList2.Items.Add("Ravi");
  31.                 DropDownList2.Items.Add("Manoj");
  32.                 DropDownList2.Items.Add("Sunil");
  33.                 DropDownList2.Items.Add("Rajesh");
  34.             }

  35.             else if (DropDownList1.Text == "Girl")
  36.             {
  37.                 DropDownList2.Items.Clear();
  38.                 DropDownList2.Items.Add("Soni");
  39.                 DropDownList2.Items.Add("Anjali");
  40.                 DropDownList2.Items.Add("Neha");
  41.                 DropDownList2.Items.Add("Rupa");
  42.             }
  43.             else
  44.             {
  45.                 DropDownList2.Items.Clear();
  46.                 DropDownList2.Items.Add("Cow");
  47.                 DropDownList2.Items.Add("OX");
  48.                 DropDownList2.Items.Add("Fox");
  49.                 DropDownList2.Items.Add("Cat");
  50.             }

  51.         }

  52.         protected void Button1_Click(object sender, EventArgs e)
  53.         {
  54.             Timer1.Enabled = true;
  55.             Image1.Visible = true;
  56.             Label1.Visible=true;
  57.         }
  58.     }
  59. }

No comments:

Post a Comment