Tuesday 31 January 2012

ASP.NET Validation Control with Example( Server Controls)

RequiredFieldValidation:
-------------------------------------------


The Required Field is use when you want to make sure that  there is a value for control before the page is submitted to the server.

It mean Server control should not be left blank..it should not keep blank.




Properties:

 

ControlToValidate: This property is used to specify the id of control which server control is validate with validation control.

 

Display: Values for this property is 1)None 2)Static  3)Dynamic

 

















Sunday 29 January 2012

Simple ASP.NET Login Page using C#



Simple ASP.NET Login Page using C#

Default.aspx:
---------------


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 483px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style1">
            <tr>
                <td class="style2">
                    UserName:</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    Password:</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
   
    </div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>




Default.aspx.cs
---------------

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(@"Data Source=A8-1\ATMIYA;Initial Catalog=login;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        con.Open();

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("select * from login1 where username='"+TextBox1.Text+"' and password='"+TextBox2.Text+"'",con);
        int nrow = Convert.ToInt32(cmd.ExecuteScalar());
        if(nrow>=1)
        {
        Session["uname"]=TextBox1.Text;
        Response.Redirect("Default2.aspx");

        }
        else
        {

            Label1.Text = "Wrong Username or Password";
        }
      
      
    }
}

Default2.aspx
------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>

Default2.aspx.cs
----------------

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["uname"]!=null)
        {
        Label1.Text = "Welcome to " + Session["uname"];
        }
    }
}

Default.aspx
--------------


Default1.aspx
----------------








demo of Simple ASP.NET Login Page using C#


Thursday 19 January 2012

Create Login Example in ASP.NET using C# with SqlServer 2005

Default.aspx
Create Login Example in ASP.NET using C# with SqlServer 2005 ------------------

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 569px;
        }
        .style3
        {
            width: 569px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style1">
            <tr>
                <td class="style3">
                    UserName:</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    Password:</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>








Default.aspx.cs
---------------------

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

    SqlConnection con = new SqlConnection(@"Data Source=A8-1\ATMIYA;Initial Catalog=login;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        con.Open();
     
     
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("select count(*) from login where username='"+TextBox1.Text+"'and password='"+TextBox2.Text+"'",con);
        int nrow=Convert.ToInt32(cmd.ExecuteScalar());
      
        if(nrow>=1)
        {

            Response.Write("Login");
            Session["uname"] = TextBox1.Text;
            Response.Redirect("Default2.aspx");
        }
        else
        {

            Response.Write("Not Login");
            Session.Clear();
        }

    }
}

Default2.aspx
---------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Label"></asp:Label>
   
    </div>
    </form>
</body>
</html>







Default2.aspx.cs
---------------

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "Welcome to " + Session["uname"].ToString();
    }
}


demo of Create Login Example in ASP.NET using C# with SqlServer 2005

Wednesday 11 January 2012

MultiView Example in ASP.NET using C#





MultiView Example in ASP.NET using C#


 Default.aspx
----------------
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Value="0">one</asp:ListItem>
            <asp:ListItem Value="1">two</asp:ListItem>
            <asp:ListItem Value="2">three</asp:ListItem>
        </asp:DropDownList>
        <br />
        <br />
        <hr />
        <asp:MultiView ID="MultiView1" runat="server">
        <asp:View ID="one" runat=server>
        <h2>This is First Contain</h2>
        <br />
            <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
        <br />
            <asp:Button ID="Button1" runat="server" Text="Button" />
       
        </asp:View>
       
        <asp:View ID="two" runat=server>
        Name: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        City: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
       
            <asp:Button ID="Button2" runat="server" Text="Button" />
       
       
        </asp:View>
       
       <asp:View ID="third" runat=server>
           <asp:RadioButtonList ID="RadioButtonList1" runat="server">
               <asp:ListItem>Male</asp:ListItem>
               <asp:ListItem>Female</asp:ListItem>
           </asp:RadioButtonList>
           <br />
          
       </asp:View>
        </asp:MultiView>
    </div>
    </form>
</body>
</html>








 Default.aspx.cs
------------------------

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

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

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = Convert.ToInt16(DropDownList1.SelectedValue);
    }
}





demo of MultiView Example in ASP.NET using C#


Thursday 5 January 2012

Create Popup Date Picker Using Asp.Net Calendar Control





Create Popup Date Picker Using Asp.Net Calendar Control


Default.aspx
-------------

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript">
        function date_show()
       
         {
             var dfield = document.getElementById("datefield");
             if (dfield.style.display = 'none')
            
              {
                  dfield.style.display = 'block';
            
             }
             else {
                 dfield.style.display = 'none';
             }
       
        }
   
    </script>
</head>
<body>
    <form id="form1" runat="server">
   
    <div id="datefield" style="display:none">
        <asp:Calendar ID="Calendar1" runat="server"
            onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
    </div>
   
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    &nbsp;</form>
    <p>
    <img src="Sunset.jpg" style="height: 26px; width: 32px" onclick="date_show()" /></p>
</body>
</html>









-------------------------
Default.aspx.cs

------------------------

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

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

    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        TextBox1.Text = Calendar1.SelectedDate.ToString("dd/mm/yy");
    }
}











demo of Create Popup Date Picker Using Asp.Net Calendar Control



Monday 2 January 2012

ScriptManager Example in ASP.NET using C#




ScriptManager Example in ASP.NET using C#


Default.aspx
-------------
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
        <asp:ScriptManager ID="ScriptManager1" runat="server">
       </asp:ScriptManager>
       <br />
       <br />
     
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
      
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            <br />
            <br />
          
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
      
        </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>









Default.aspx.cs
----------------

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

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Current Time==>" + System.DateTime.Now.ToLongTimeString();
    }
}














demo of ScriptManager Example in ASP.NET using C#