Friday, 27 January 2023

IsPostBackEvent in ASP.NET

 

IsPostBackEvent in ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IsPostBackEvent.aspx.cs" Inherits="ASPNETALL.IsPostBackEvent" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <strong>First Name :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            <strong>Last Name :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                <br />
                City :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>
            <asp:DropDownList ID="ddlCity" runat="server" Height="16px" Width="116px">
            </asp:DropDownList>
            <br />
            <br />
            <asp:Button ID="btnReg" runat="server" OnClick="btnReg_Click" Text="Registration" />
        </div>
    </form>
</body>
</html>

IsPostBackEvent.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ASPNETALL
{
    public partial class IsPostBackEvent : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadCityDropDownLIst();
            }
        }
        public void LoadCityDropDownLIst()
        {
            ListItem li1 = new ListItem("Uttar Pradesh");
            ddlCity.Items.Add(li1);
            ListItem li2 = new ListItem("Bihar");
            ddlCity.Items.Add(li2);
            ListItem li3 = new ListItem("Jharkhand");
            ddlCity.Items.Add(li3);
        }
        protected void btnReg_Click(object sender, EventArgs e)
        {
        }
    }
}

0 comments

Post a Comment