ASP.Net [Version 4.5.1]
Basic-1
What is ASP.Net ?
Ans: Asp.Net stand for active server page for .Net . It is provided as a framework for building web applications and it is very important to understand that ASP.Net is not a language or pakages, it is separate Framework.
CRUD OPERATIONS:
1) Page Login:
LoginPage.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoginPage.aspx.cs" Inherits="LoginPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
    
<asp:Label ID="Label1" runat="server" Text="User Name:"></asp:Label>
       
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Password:"></asp:Label>
         
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<br />
<br />
<br />
 <br />
<asp:Button ID="btnLogin" runat="server" onclick="btnLogin_Click" Text="Login" />
           
<asp:Button ID="btnSignup" runat="server" Text="Signup" OnClick="btnSignup_Click" />
    
</div>
</form>
</body>
</html>
        
        
       
    
    
       
       
       
                
          
           
        
        
   
    
    
Basic-1
What is ASP.Net ?
Ans: Asp.Net stand for active server page for .Net . It is provided as a framework for building web applications and it is very important to understand that ASP.Net is not a language or pakages, it is separate Framework.
CRUD OPERATIONS:
1) Page Login:
LoginPage.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoginPage.aspx.cs" Inherits="LoginPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="User Name:"></asp:Label>
       
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Password:"></asp:Label>
         
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<br />
<br />
<br />
 <br />
<asp:Button ID="btnLogin" runat="server" onclick="btnLogin_Click" Text="Login" />
           
<asp:Button ID="btnSignup" runat="server" Text="Signup" OnClick="btnSignup_Click" />
</div>
</form>
</body>
</html>
.........................
.........................
LoginPage.aspx.cs:
using System;
using System.Collections.Generic;   //@ ujjwal paul programming @
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient; // use this must
using System.Configuration;
public partial class LoginPage : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnLogin_Click(object sender, EventArgs e) // Database-paulDB ; TableName-Logintbl
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Logintbl where UserID='" + txtUserName.Text + "' And Password='" + txtPassword.Text + "' ", con);
        SqlDataReader dr;
        dr = cmd.ExecuteReader();
        while (dr.Read())
            if (txtUserName.Text == dr[0].ToString() && txtPassword.Text == dr[1].ToString()) // dr[0] =TextBox1 . dr[1]= TextBox2
            {
                Response.Redirect("WelcomeToLogin.aspx");
            }
            else
            {
                Response.Write("<script>alert ('Your UserName or Password  Wrong Enter')</script>");
            }
        con.Close();
    }
    protected void btnSignup_Click(object sender, EventArgs e)
    {
        Response.Redirect("UserRegistration.aspx");
    }
..........................................
UserRegistration.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserRegistration.aspx.cs" Inherits="UserRegistration" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
            border: 5px solid #FF0000;
        }
        .auto-style2 {
            width: 168px;
        }
        .auto-style5 {
            width: 220px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblReg" runat="server" Text="User Registration Form" style="font-weight: 700; color: #0000FF"></asp:Label>
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">First Name :</td>
                <td class="auto-style5">
                    <asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
                </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td class="auto-style2">Last Name :</td>
                <td class="auto-style5">
                    <asp:TextBox ID="txtLName" runat="server"></asp:TextBox>
                </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td class="auto-style2">Gender :</td>
                <td class="auto-style5">
                    <asp:RadioButton ID="RadioButton1" runat="server" GroupName="Rbtn" Text="Male" />
                    <asp:RadioButton ID="RadioButton2" runat="server" GroupName="Rbtn" Text="Female" />
                </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td class="auto-style2">Address :</td>
                <td class="auto-style5">
                    <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" ></asp:TextBox>
                </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td class="auto-style2">Mobile No :</td>
                <td class="auto-style5">
                    <asp:TextBox ID="txtMobile" runat="server" TextMode="Number"></asp:TextBox>
                </td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td class="auto-style2">Designation :</td>
                <td class="auto-style5">
                    <asp:DropDownList ID="ddlDesignation" runat="server">
                        <asp:ListItem Value="Developer">Developer</asp:ListItem>
                        <asp:ListItem Value="Designaer">Designaer</asp:ListItem>
                        <asp:ListItem Value="Tester">Tester</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td class="auto-style2"> </td>
                <td class="auto-style5"> </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td class="auto-style2"> </td>
                <td class="auto-style5"> </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td class="auto-style2"> </td>
                <td class="auto-style5"> </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
            <tr>
                <td class="auto-style2"> </td>
                <td class="auto-style5">
                    <asp:Button ID="btnSubmitRegistration" runat="server" OnClick="btnSubmitRegistration_Click" Text="Submit" Width="205px" />
                </td>
                <td> </td>
                <td> </td>
                <td> </td>
                <td> </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
..........................................
UserRegistration.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class UserRegistration : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnSubmitRegistration_Click(object sender, EventArgs e)
    {
            string gen = "";
            if (RadioButton1.Checked)
            { gen = "Male"; }
            else if(RadioButton2.Checked)
            { gen = "Female"; }
            string q = String.Format("insert into Registrationtbl(FName,LName,Gender,Address,Mobile,Designation) Values('" + txtFName.Text + "' , '" + txtLName.Text + "','"+gen+"','" + txtAddress.Text + "',"+txtMobile.Text+",'" + ddlDesignation.SelectedValue + "')");
            SqlCommand cmd = new SqlCommand(q,con);
            con.Open();
        if(cmd.ExecuteNonQuery()!=0)
        {
            Response.Write("Data Save into Database");
        }
        else
        {
            Response.Write("Data Failed to Insert");
        }
        con.Close();
    }
}
.....................
WellcomeToLoginPage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WelcomeToLogin.aspx.cs" Inherits="WelcomeToLogin" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Image ID="Image1" runat="server" Height="341px" ImageUrl="~/pic1.jpg" Width="656px" />
    </div>
    </form>
    <p>
        WELCOME TO Login Page :</p>
</body>
</html>
........................................
WelcomeToLoginPage.aspx.cs
No Codind
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Web.Config:
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="constr" connectionString="Data Source=UJJWAL; Initial Catalog=paulDB; user id=sa;password=123"/>
  </connectionStrings>
    <system.web>
      <compilation debug="true" targetFramework="4.5.1" />
      <httpRuntime targetFramework="4.5.1" />
    </system.web>
</configuration>
No comments:
Post a Comment