Asp.net

·

19 min read

→ When we browse any website like gmail.com (or) any other, we find a web page that will be opened like

→ In this the designing of the page is like creating textboxes, buttons, etc,.. is performed by using HTML, CSS

→ The pages developed using HTML & CSS are called as static web pages because HTML & CSS is just used for designing & styling, HTML & CSS can not used to implement the validation like user entered username (or) not, password (or) not whether password is 8 characters (or) not etc,..

1. Client

A client is a software component (or) tool using which request is submitted to the server over the internet Example of Client Google chrome Microsoft edge Opera Firefox etc… Client side script code

→ The code that will run with in the client (or) browser is known as client side scripting code Client side programming language

→ The programming language that is used to write the client side scripting code is known as client side scripting programming language Example of client side scripting languages are 1. VB script 2. J Script 3. Java Script

→ Java script is the most popularly used client side programming language by the industry

→ Java script is developed by Netscape company in support to their browser Netscape Navigator

2. Server

→ A server is a software component known as web server

→ The role of web server is 1. Capable to store one (or) more web servers within it 2. Takes request from the client, process the request & deliver the response back to client Server side scripting code

→ The code that will run on the web server over the internet is known as server side scripting code Server side Technologies → The technology that are used to develop the server side scripting code are known as server side technologies

Example of Server side technologies are

ASP

→ Active Server Pages

ASP.NET → Active Server Pages for .Net

ASP.NET Core → Active Server Pages for .Net Core

JSP → Java Server Pages

PHP → Personal Home Page

DJango → Every server side technology will use one (or) other programming languages to write the code like

ASP → VB

ASP.NET → C#.Net,

VB.Net ASP.NET Core → C#.Net,

VB.Net JSP → Java

PHP → C / C++

DJango → Python

What is ASP.Net?

ASP.NET is a server side technology used to build interactive & dynamic web applications

ASP.NET & C# code will run on the web server only

Any browser can not understand ASP.Net & C# code

→ Once server side technology code is run at web server the code is converted into client understandable format & deliver to client

What is Rendering?

→ Rendering is the process (or) mechanism of converting the server side code into client understandable format ie. HTML, CSS & Java Script

Creating a website in ASP.NET from visual studio

→ Open visual studio .Net

→ Click on Continue without code

→ Click on File

→ Click on New

→ Click on Projec

(or)

→ Click on Create a new Project

→ Type ASP.NET web in search option

→ Choose ASP.NET Web Application (.NET Framework) with C# programming language template

→ Click on Next

→ Type the Web Application name (For example: ASP.NET_Web_Application_by_MaheshSir)

→ Choose the location to save

→ Choose the Framework ( u.Net Framework 4.7.2 )

→ Click on Create

→ Choose the Empty template ⇒ Make sure that in Advanced → Configure for HTTPS is Checked

→ Click on Create, this will create Web Application with the name ASP.NET_Web_Application_by_MaheshSir

Adding a new Web page to the Web Application

→ Goto Solution Explorer

→ Select the Solution click with right mouse button

→ Click on Add

→ Click on New Item… (or)

→ Press the Key Ctrl + Shift + A from keyboard at a time

→ Select Web Form from the template, type the Web Form page name as Home.aspx

→ Click on Add, this will create web page with the name Home.aspx

→ Every web page will contain two file associated with it

1. .aspx 2. .aspx.cs

→ .aspx file will contain designing code & .aspx.cs file will contain programming code

→ Here .aspx means Active Server Page that can be run on X Processor & in X operating system

→ .aspx page will contain two parts 1. Design 2. Source

→ Source part will contain the code for the design part will contain the physical appearance of the web page

→ Goto source part type the following code inside the div tags

→ run the application & check

Difference between HTML Controls & ASP.Net standard control

Sl.No HTML Control ASP.Net Standard Control 1 All HTML controls run at client side All ASP.Net standard controls run at server side 2 Can be made to run at server side Can not be made to run at client side 383 by adding runat=”server” attribute rather equivalent HTML code is generated on Rendering 3 Rendering is not required Rendering is required 4 Execution is faster Execution is slow 5 Do not contain any class for the controls Contains a separate class for each control 6 Do not support object oriented programming Support object oriented programming feature 7 Do not maintain state Maintain state

Sl.NoHTML ControlASP.Net Standard Control
1All HTML controls run at client sideAll ASP.Net standard controls run at server side
2Can be made to run at server side by adding runat=”server” attributeCan not be made to run at client side rather equivalent HTML code is generated on Rendering
3Rendering is not requiredRendering is required
4Execution is fasterExecution is slow
5Do not contain any class for the controlsContains a separate class for each control
6Do not support object oriented programmingSupport object oriented programming feature
7Do not maintain stateMaintain state

How to create a master page

Go to visual stdio and select Web form Master Page then one page visibal front of you then one <div></div> tag also there in div you create one our div then writ there

you write any thing in your master page it will show all the pages

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs" Inherits="MAsterPageEx.MasterPage" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <div class="Wrapper">   //this div allredy avilable if you want any change in css so you use class
            <div class="header"> //it is a header part 
                <h1>This is a header of my new website ! !</h1>
            </div> //close header
          <div class="content">  //is div is alredy avilable here we don't write any thing we are writing other page
           <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

           </asp:ContentPlaceHolder>
           </div>

            <div class="footer"> // this is a footer div
                <h3>This is a footer my website @2018</h3>
            </div> // close footer div
        </div>   // first div is close
    </form>
</body>
</html>

Adding css file Go to master page and in hade tag

or

catch css file and drop in head tag in master page

 <link href="Style.css" rel="stylesheet" type="text/css" />

if you want to your form take input password textmode ="pasword"

Validation

Types of validation

  • CompareValidation

  • CustomValidator (its meens user defined validation)

  • RangeValidator

  • RagularExpression

  • RequiredFieldValidator

  • ValidationSummary

if you want to your form submit then it will show one popop message then write butto this code `

Page.ClientScript.RegisterStartupScript(this.GetType(),"Scripts","<script>alert('Your form has been submited !!')</script>");

if your page showing this type error

Then write goto solution explorer and web.config

               // that page showing this type after 3 or 4  line 


<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />

  </appSettings>

then then add a new line

  <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>

All the validation show in one box it call validation sammry

ISPOSTBACK PROPERTY:-

POSTBack:-

Postback is actually sending all the information form clint to web server, then web server process those contents and returns back to the client.

Most of the time asp control will cause a post back (e.g: buttonclick ) but in some case postback is not happen (e.g: ListBoxlndexChanged, RadioButtonChecked etc)

Whan a page loads for the very first time then IsPostBack Propperty is False.

Whene a page load for the second time or more then second time then IsPostBack Property is true.

Whenever we click the button, page load and postBack occurs.

Normally we used IsPostBack property in page_load event.

State Managment:-

-> HTTP PROTOCOL IS A STATELESS PROTOCOL.

-> Web Application is Stateless.

-> Web server Does not have any idea about the Requests From Whwre They Comming.

On Each Request Web pages Are Created And Destroyed.

TYPE OF STATEMANEGMENT

View State:-

View State is a method to store the value of page and controls between round trips.

It is a Page-Lavel state management technique.

In View state we are only one page data restore and we not access data from one page to another page

                         // submit and restore
using System;

namespace StateManegment
{
    public partial class StatM : System.Web.UI.Page
    {
        string a, b;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRestore_Click(object sender, EventArgs e)
        {
            if (ViewState["user"] != null)
            {
                txtUSerName.Text = ViewState["user"].ToString();
            }
            if (ViewState["Pass"] != null)
            {
                txtPass.Text = ViewState["Pass"].ToString();
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ViewState["user"] = txtUSerName.Text;
            ViewState["Pass"]=txtPass.Text;

            txtUSerName.Text=string.Empty;
            txtPass.Text=string.Empty;
        }
    }
}

Session state:-

Asp.Net session state enables you to store and retrieve values for a user as the navigates Asp.Net pages in a Web application

Create session

                         //sec.aspx.cs
using System;


namespace Secssion2
{
    public partial class Ses1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtName.Text !=null)
            {
                  // Session.Add("Name", txtName.Text);
                Session["Name"] = txtName.Text;    //creating session
                Response.Redirect("Welcome.aspx");
            }
            else
            {
                Label1.Text = " plz Enter Name";
            }
        }
    }
}

                       //Welcome Page.aspx.cs
using System;

namespace Secssion2
{
    public partial class Welcome : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Name"] != null)
            {
                Label1.Text = Session["Name"].ToString();
            }
            else
            {
                Response.Redirect("Sec1.aspx");
            }



        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            Response.Redirect("session2.aspx");
        }
    }
}

//Acording to need we are adding new pages and add session that pages

Create session timeout

Go To web.config and write this line

After 1 minut it will send to agen login page

Application State

In a Web Applicatio,Data can be store at 3 levels.

  1. At The Page Lavel (Webform Level).

a viewstate

  1. At The session level (User level) (Means one user is login we are display that user multiple pages)

    a. Session Stste

  2. At The Applicatio Level

A .Application State

1.Page Level or Webform level:

Data Stored in page lavel is available only on that particular page.Another page cannot access or receive that information.

2.Session Level or User Level:

Data Stored in session Level variable is available only for a single user and is shared and navigate among the diffrent pages for that User.This Data is not share among the different users.

Application Level:

Data Stored in application level then That data is Avilable on that particular page , as well as across different pages and also across different user. In other words data is available for every user which is using that application.

means all the user whaching same data if he using diffrent browser it will watch same data no matter user use which browser

Why we use application state see this example

here i have run one project

Then i have enter any name then it will go welcome page

here welcome url i well send newt tab in same browser it will open welcome

But here other user use like diffren browser then it will send to you agen login page that by we are using Application state diffrent browser

In Application state copy url and send other browser it will showing url data it will sending to you diffrent pages

After using Application state it will show boath browser same page

Query String

→ Query String is a collection of characters input or group of keyword that send request to the web server.

→ A Query String is helpful we want to transfer a value form one page to another. When we need to pass conteb=nt between the HTML page or aspx Web Forms in the context of ASP.NET,you can accntaining page.

→ It Containing in the HTTP request for a specific URL.

→ These request sepecifid by the values following the ? (question mark).

Query string-Limitation-

→ Query string have a length limitation because of this limitation when you have to send a lot of information it won’t work. // we can only send data 2 or 4 mb it is a very limitd memory

→ Anpther limitation is that querystring data is directly visible to user so this information can be falsified by malicious user and it leading to security problems.

                                //   Query_SPage1.aspx.cs  //
using System;

namespace QueryString_R
{
    public partial class Quary_SPAge1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmiot_Click(object sender, EventArgs e)
        {
            Response.Redirect("Query_S_Page2.aspx?id="+txtId.Text + "&name=" + txtName.Text + "&Age="+txtAge.Text);
                                                      // is i need to 2 or more data add in a same time then wb are using  this (&) simbale
        }
    }
}

                             // QueryS_Page2.aspx.cs  //
using System;
namespace QueryString_R
{
    public partial class Query_S_Page2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtId.Text = Request.QueryString["id"];
            txtName.Text = Request.QueryString["name"];
            txtAge.Text = Request.QueryString["Age"];
        }
    }
}

OutPut

A web page displaying student details: Student ID "1001", Student Name "Sumit", and Student Age "21". The URL shown in the browser's address bar includes parameters for ID, name, and age. The text "Page 2" is handwritten in orange at the bottom left of the page.

The Repeater Control is used to display a repeated List of Items that are bound to the control may be bound to a database table , An xml file, or Another list of items.

→ Repeater is a data bind control. data bind controls are container controls. data binding is the process of creating a Link between the data source and presentation ui to display the data . asp.net provides rich and wide variety of controls, which can be bound to the data.

→ Just Like Gridview, a Repeater control is Also a Data -Bound Control

→ To Bind Data we can use Datasource property and invoke databind() Method.

By Default, a repeater control will not render any thing if templates are not specified but where as with gridview control the data form the underlying datasource will be rendered in a Tabluar format

→ Gridview control is more suitable and desigend for displaing data in a tabular format , where as repeater control is used when you want to have complete control over how you want the data to be rendered.

→ By Default, the repeater cntrol dose not offer editing,paging and sorting capabilties but as gridview control does. however with a bit of effort and code it is possible to implement these featurese using a repeater control.

One Side is Grid view and second side is Repeater

                        // Source Code

// We can desigine datagrid view write this typecode and automatically also
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Repeter_Online.aspx.cs" Inherits="Repeter.Repeter_Online" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table class="auto-style1">
                <tr>
                    <td>
                        <asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" GridLines="None" ShowHeader="False">
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <table border="1">
                                            <tr>
                                                <td>Id
                                                </td>
                                                <td>
                                                    <asp:Label ID="Label1" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>Name
                                                </td>
                                                <td>
                                                    <asp:Label ID="Label2" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>Gender
                                                </td>
                                                <td>
                                                    <asp:Label ID="Label3" runat="server" Text='<%#Eval("Gendre") %>'></asp:Label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>City
                                                </td>
                                                <td>
                                                    <asp:Label ID="Label4" runat="server" Text='<%#Eval("City") %>'></asp:Label>
                                                </td>
                                            </tr>
                                        </table>
                                        <br />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </td>
                    <td>
                        <asp:Repeater ID="Repeater1" runat="server">

                            <ItemTemplate>
                                <table border="1">
                                    <tr>
                                        <td>Id
                                        </td>
                                        <td>
                                            <asp:Label ID="Label1" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Name
                                        </td>
                                        <td>
                                            <asp:Label ID="Label2" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Gender
                                        </td>
                                        <td>
                                            <asp:Label ID="Label3" runat="server" Text='<%#Eval("Gendre") %>'></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>City
                                        </td>
                                        <td>
                                            <asp:Label ID="Label4" runat="server" Text='<%#Eval("City") %>'></asp:Label>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                            <SeparatorTemplate>
                                <br>
                                </br>
                            </SeparatorTemplate>

                        </asp:Repeater>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
                          // cs Code
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Repeter
{
    public partial class Repeter_Online : System.Web.UI.Page
    {
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connect"].ToString());
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = GetData();
            GridView1.DataSource = dt;
            GridView1.DataBind();

            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }

        DataTable GetData()
        {
            cn.Open();
            SqlDataAdapter da = new SqlDataAdapter("Select * from Emp2", cn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
            cn.Close();
        }
    }
}

When should you use gridview and when should you use reapeter?

→ A Repeater Control is a very light control, and if you want to have the complete control over how the data is rendered,and if you dont’t want editing, paging or sorting capabilities, then repeater should be your choice.

→ On The other Hand oif you want the data to be rendered automatically in a tabular format and you also need editing, deleting, paging and sorting capabilites,then gridview should be your choice

Drop Down in asp.NET

DropDownList Control ois a collection of listItem objects.

The ListItem can be added to the DropDownList at the design time or at the runtime.

if we want a particular to be selected in the DropDownList,set the Selected of the ListItem object to true.

To hide a List Item in The DropDownList, set the Enabled prpoerty to false.

Following Controls are a collection of ListItem Objects.

  • CheckBoxList

  • RadioButtonList

  • BulletedList

  • ListBox

The ListItem can be added to the DropDownList at the design time

                      //Source
              //Adding Value at a desiging time      
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DropDown.aspx.cs" Inherits="Demo3.DropDown" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <h2> Drop Down </h2>
        <div>
            <asp:DropDownList ID="DropDownList1" runat="server">
               <asp:ListItem Value="0"> -Select City- </asp:ListItem>
               <asp:ListItem Value="1"> HYD </asp:ListItem>
               <asp:ListItem Value="2"> CHE </asp:ListItem>
               <asp:ListItem Value="3"> BGL </asp:ListItem>
               <asp:ListItem Value="4" Enabled="fals"> PUNE </asp:ListItem>   // it meens item is avilable but not display in dropdown list
            </asp:DropDownList>

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

Adding Value At a Run Time

                         // Adding value at a run time 
             // .cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo3
{
    public partial class DropDown : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ListItem L1 = new ListItem("HYD", "1");    // Text="HYD" value="1"
            ListItem L2 = new ListItem("CHE", "2");
            ListItem L3 = new ListItem("BGL", "3");
            ListItem L4 = new ListItem("PUNE", "4");

            DropDownAT_a_RUNTIME.Items.Add(L1);
            DropDownAT_a_RUNTIME.Items.Add(L2);
            DropDownAT_a_RUNTIME.Items.Add(L3);
            DropDownAT_a_RUNTIME.Items.Add(L4);

            DropDownAT_a_RUNTIME.Items[1].Selected=true;  // It meens page will be load then fist index means HYD Atomatic salect

        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo3
{
    public partial class DropDown : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)                   // it meens page load first time it will display this property
                                              // and any click then it will not repiding valus secon time 
            {
                ListItem l1 = new ListItem("HYD", "1");
                ListItem l2 = new ListItem("CHE", "2");
                ListItem l3 = new ListItem("BGL", "3");
                ListItem l4 = new ListItem("PUNE", "4");

                DropDownAT_a_RUNTIME.Items.Add(l1);
                DropDownAT_a_RUNTIME.Items.Add(l2);
                DropDownAT_a_RUNTIME.Items.Add(l3);
                DropDownAT_a_RUNTIME.Items.Add(l4);
            }

        }
    }
}

Accessing DropDown ListItem

To Access

  • Selected Item Text: DropDownList.SelectedItem.Text

  • Selected Item Value: DropDownList.SelectedItem.Value

  • OR

  • Select Item Value: DropDownList.SelectedValue

  • Select Item Value: DropDownList.SelectedIndex

Selected Item

widthout Selected

For Text

                      // If we want text in dropdown list
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo3
{
    public partial class DropDown : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedValue == "0")   // it showing error message plese select city
            {
                lblMessage.Text = "Plese Select City";
            }
            else
            {
                lblMessage.Text = "Your Selected city is" + DropDownList1.SelectedItem.Text;   // it will display that city user selectd

            }
        }
    }
}

For Value

                      // If we want text in dropdown list
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo3
{
    public partial class DropDown : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
             {
                DropDownList1.SelectedIndex = 1;  // it will set  text that index value is 1
             }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedValue == "0")   // it showing error message plese select city
            {
                lblMessage.Text = "Plese Select City";
            }
            else
            {
                lblMessage.Text = "Your Selected city is" + DropDownList1.SelectedItem.Text +"<br/>";   // it will display that city user selectd
                 lblMessage.Text = "Your Selected city is" + DropDownList1.SelectedItem.Value;   // It will showing value
                 lblMessage.Text = "Your Selected city is" + DropDownList1.SelectedValue;        // It will showing value

            }
        }
    }
}

LISTBOX CONTROL

  • ListBox Control used to store the multiple item and allow user to select or multiple item form listbox control.

  • ListBox control is same as dropdownlist control.

  • The dropdownlist control allow user to select maximum only one item at a time,on other hand listbox control allow user to select ormultiple item same time

  • It is a collection of ListItem boject like DropDownList, CheckBoxList,RadioButtonList etc.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Section4
{
    public partial class ListBoxExample : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (ListBox1.SelectedIndex == 0)
            {
                Response.Write("PLZ Select Contry");
            }

            else
            {

                Response.Write("Your selected Item is " + ListBox1.SelectedItem.ToString() + "<br/>");
                Response.Write("Your selected value is " + ListBox1.SelectedValue.ToString() + "<br/>");
                Response.Write("Your selected Index is " + ListBox1.SelectedIndex.ToString() + "<br/>");

            }

        }
    }
}

Multiple Value

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Section4
{
    public partial class ListBoxExample : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (ListBox1.SelectedIndex == 0)
            {
                Response.Write("PLZ Select Contry");
            }

            else
            {
                foreach(ListItem li in ListBox1.Items)
                {
                    if (li.Selected)
                    {
                        Response.Write("Your selected Item is " + li.ToString() + "<br/>");
                        Response.Write("Your selected value is " + li.Value + "<br/>");
                        Response.Write("Your selected Index is " + ListBox1.Items.IndexOf(li) + "<br/>");
                        Response.Write("<br/>-----------------------------");
                    }
                }

            }

        }
    }
}

ListBox Property

  • Rows

  • SelectionMode

  • Font

  • ForeColor

  • BackColor

  • Enabled

Binding ListBox With Database In Asp.Net

JQUERY AJAX LOAD() METHOD

The jQuery load() method is a simple,but powerful AJAX method.

The load() method loads data from a server and puts the returend data into the selected element.

  • Syntax:

  • $(selector).load(URL,data,callback);

  • The required URL oarameter specifies the URL you wish to load.

  • The optional data parameter specifies a set set of querystring key/value pairs to send along with the request.

  • The optional callback parameter is the name of a function to be executed after the load() method is completed.

  • The optional callback parameter specifies a callback function to run whenthe load() method is completed. The callback function can have different parameters:

  • responseTxt- contains the resulting content if the call succeeds

  • statusTxt - Contains the status of the call

  • xhr contains the XMLHttpRequest object

                     // aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Load_Method_AJAX.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input type="button" id="btn" value="click to Get Data"/>
            <br />
            <div id="result">

            </div>
        </div>
    </form>
    <script src="Scripts/JQUERY.js"></script>
    <script>
        $(document).ready(function (){
            $("#btn").click(function () {
                $("#result").load("Pages/HtmlPage1.html", function (responseTxt, statusTxt, xhr){

                    alert("responseTxt");
                    alert("statusTxt");
                    alert("xhr");
                });
            });
        });
    </script>
</body>
</html>

Go To JQUERY website and download code and create a nue java script file and past code when you copy code in JQUERY website