Sunday, 31 March 2013

Performing Client side validations using Javascript in asp.net

<%@ 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></title>
<script type="text/javascript" language="javascript">
    function isvalidate() {
        var UserName = document.getElementById('<%= Txtname.ClientID %>').value;
        var pwd = document.getElementById('<%= txtpwd.ClientID %>').value;
        if (UserName == "") {
            alert("Enter UserName");
            return false;
        }
        if (pwd == "") {
            alert("Enter Your Password");
            return false;
        }
    }
   
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      UserName  : <asp:TextBox id="TxtName" runat="server"/>
      Password   : <asp:TextBox id="txtpwd" runat="server"/>
   <asp:Button id="btnLogin" runat="server" Text="Login" OnClientClick="isvalidate()"></asp:Button>
    </div>
    </form>
</body>
</html>

Saturday, 30 March 2013

Search and show Gridview data in Pop up Window

This is a simple task for searching grid view and views the details of in grid view data in popup window (new browser).

Search.aspx (.aspx)

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

<!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">
        .form
        {
            background-color: skyblue;
        }
        .div
        {
            right: 302px;
            left: 300px;
            height: 112px;
        }
        .div1
        {
            right: 302px;
            left: 10px;
            height: 112px;
        }
    </style>
</head>
<
body class="form">
    <form id="form1" runat="server">
    <div class="div" style="position: absolute; top: 42px;">
        <table>
            <tr>
                <td align="center">
                    <b>Know Your Application Status </b>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Panel ID="Panel1" runat="server">
       <asp:RadioButtonList ID="RadioButtonList1" runat="server"
                            RepeatDirection="Horizontal" Width="372px">
        <asp:ListItem Value="Id" Selected="True">Application ID</asp:ListItem>
         <asp:ListItem Value="Name">Applicant Name</asp:ListItem>
           <asp:ListItem Value="No">House Number</asp:ListItem>
                        </asp:RadioButtonList>                   
                    </asp:Panel>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <asp:TextBox ID="txtSearchContect" runat="server" Width="197px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <asp:Button ID="btnsearch" runat="server" Text="Search" OnClick="btnsearch_Click" />
                </td>
            </tr>
        </table>
    </div>
    <div class="div1" style="position: absolute; top: 200px;">
        <table>
            <tr>
                <td align="left">
                    <asp:GridView ID="gvappdetails" AutoGenerateColumns="False" runat="server" Style="margin-left: 0px"
                        Width="916px" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
                        CellPadding="4" GridLines="Horizontal">
                        <RowStyle BackColor="White" ForeColor="#333333" />
                        <Columns>
                         <asp:BoundField HeaderText="APP ID" DataField="APPID" />
                            <asp:BoundField HeaderText="NAME" DataField="NAME" />
           <asp:BoundField HeaderText="RELATION NAME" DataField="RELATIONNAME" />

                    <asp:BoundField HeaderText="AGE" DataField="AGE" />
                <asp:BoundField HeaderText="HOUSE NO" DataField="HOUSENO" />
                            <%--<asp:BoundField HeaderText="AC NUMBER" DataField="[ACNUMBER&NAME]" />--%>
                            <asp:BoundField HeaderText="PART NO" DataField="PARTNO" />
                           <asp:TemplateField HeaderText="View Status?">
                                <ItemTemplate>
                                    <a href="javascript:window.open('Searchdetails.aspx?AppId=<%# Eval("APPID") %>','NewPage','width=400,height=500');">
                                        View Status</a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="White" ForeColor="#333333" />
                        <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</
html>

gridview.gif

Code Behind File (.aspx.cs)

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

public partial class Search : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Administrator\\My
Documents\\Visual Studio 2008\\WebSites\\WebSite2\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True"
);
    public void fillgrid()
    {
        SqlCommand cmd = new SqlCommand("select APPID,NAME,RELATIONNAME,AGE,HOUSENO,PARTNO from APPLICANTDETAILS", con);
        DataSet ds = new DataSet();
        con.Open();
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        dap.Fill(ds, "APPLICANTDETAILS");
        gvappdetails.DataSource = ds.Tables[0].DefaultView;
        gvappdetails.DataBind();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        //fillgrid();
    }   
    protected void btnsearch_Click(object sender, EventArgs e)
    {
     switch (RadioButtonList1.SelectedItem.Value)
        {
            case "Name":
                SqlCommand cmd = new SqlCommand("select APPID,NAME,RELATIONNAME,AGE,HOUSENO,PARTNO from APPLICANTDETAILS where Name='"
+ txtSearchContect.Text + "'", con);
                DataSet ds = new DataSet();
                con.Open();
                SqlDataAdapter dap = new SqlDataAdapter(cmd);
                dap.Fill(ds, "APPLICANTDETAILS");
                gvappdetails.DataSource = ds.Tables[0].DefaultView;
                gvappdetails.DataBind();
                break;
            case "No":
                SqlCommand cmd1 = new SqlCommand("select APPID,NAME,RELATIONNAME,AGE,HOUSENO,PARTNO from APPLICANTDETAILS where
HOUSENO='"
+ txtSearchContect.Text + "'", con);
                DataSet ds1 = new DataSet();
                con.Open();
                SqlDataAdapter dap1 = new SqlDataAdapter(cmd1);
                dap1.Fill(ds1, "APPLICANTDETAILS");
                gvappdetails.DataSource = ds1.Tables[0].DefaultView;
                gvappdetails.DataBind();
                break;
            default:
                SqlCommand cmd2 = new SqlCommand("select APPID,NAME,RELATIONNAME,AGE,HOUSENO,PARTNO from APPLICANTDETAILS where
APPID='"
+ txtSearchContect.Text + "'", con);
                DataSet ds2 = new DataSet();
                con.Open();
                SqlDataAdapter dap2 = new SqlDataAdapter(cmd2);
                dap2.Fill(ds2, "APPLICANTDETAILS");
                gvappdetails.DataSource = ds2.Tables[0].DefaultView;
                gvappdetails.DataBind();
                break;

        }
    }

}
SearchDetails.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Searchdetails.aspx.cs" Inherits="Searchdetails" %>
<!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">
        .span
        {
            right: 302px;
            left: 300px;
            height: 112px;
        }
        .body
        {
            background-color: skyblue;
        }
        .td{}
    </style>
</head>
<
body class="body">
    <form id="form1" runat="server">
    <div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <asp:Label ID="Label1" runat="server" ForeColor="Red" Text="E - REGISTRATION USER STATUS"></asp:Label>
        <br />
        <table>
            <tr>
                <td>
                    APPLICATION ID
                </td>
                <td>
                    <asp:Label ID="lblappid" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    NAME
                </td>
                <td>
                    <asp:Label ID="lblname" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    RELATION NAME
                </td>
                <td>
                    <asp:Label ID="lblrelationname" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    AGE
                </td>
                <td>
                    <asp:Label ID="lblage" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    HOUSE NO
                </td>
                <td>
                    <asp:Label ID="lblhno" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    PART NUMBER
                </td>
                <td>
                    <asp:Label ID="lblpartno" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    Application Date
                </td>
                <td>
                    <asp:Label ID="lblapplicationdate" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    STATUS
                </td>

                <td>
                    <asp:Label ID="lblstatus" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    REMARKS
                </td>
                <td>
                    <asp:Label ID="lblremarks" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td align="right">
                  <asp:Button ID="btnprint" runat="server" Text="Print" />
                 </td>
                <td>
                    <asp:Button ID="btnexit" runat="server" Text="Exit" />
                </td>
            </tr>
         </table>
    </div>
    </form>
</body>
</
html>

gridview1.gif

Code Behind file (SearchDetails.aspx.cs)

public partial class Searchdetails : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Administrator\\My
Documents\\Visual Studio 2008\\WebSites\\WebSite2\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True"
);
    protected void Page_Load(object sender, EventArgs e)
    {
        string sql = "select * from APPLICANTDETAILS where APPID='" + Request.QueryString["AppId"] + "'";
        SqlCommand cmd = new SqlCommand(sql, con);
        con.Open();
        SqlDataReader Dr = cmd.ExecuteReader();
        if (Dr.Read() == true)
        {
            lblappid.Text = Dr[0].ToString();
            lblname.Text = Dr[1].ToString();
            lblrelationname.Text = Dr[2].ToString();
            lblage.Text = Dr[3].ToString();
            lblhno.Text = Dr[4].ToString();
            lblpartno.Text = Dr[6].ToString();
            lblapplicationdate.Text = Dr[7].ToString();
            lblstatus.Text = Dr[8].ToString();
            lblremarks.Text = Dr[9].ToString();
        }      
    }
}

Thursday, 28 March 2013

How To Load User Controls Dynamically in ASP.Net3.5

To dynamically create an instance of User Control we have to use Page.LoadControl () method which returns an instance of the Control class. And also the PlaceHolder control which acts as a container of controls.
 
Below is the code to show all the User Controls present in Application's UserControls folder
in a single web page.
First of all we have to add a PlaceHolder control.
 
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
.
//UserControls is the folder which contains all the user controls used by the application.
const string userControlFolder = "~/UserControls";
 
 
 
protected void Page_Load(object sender, EventArgs e
{
 
        ArrayList oArrayList = GetControlPaths();
 
        foreach (string path in oArrayList)
        {
            Control oControl = Page.LoadControl(path);
            PlaceHolder1.Controls.Add(oControl);
        }      
    }
 
 
     // This method returns an ArrayList which holds the virtual path of all the User Controls.
    private ArrayList GetControlPaths()
    {
        ArrayList userControlPath = new ArrayList();
 
 //This string array contains only the list of files having .ascx extension which is the extension for user control
string[] files = Directory.GetFiles(MapPath(userControlFolder),"*.ascx");
 
       foreach (string oFile in files)
       {
userControlPath.Add(Path.Combine(userControlFolder,Path.GetFileName(oFile)));
       }
 
        return userControlPath;
    }

Friday, 22 March 2013

How to do the Registration and Login By Roles using ASP.NET


In this article we will learn how to register a user having multiple roles. In the example here we have the three roles "Admin", "Free User" and "Paid User". After successful registration we can also login to the system. During login we can redirect to various webpages depending on their corresponding roles.

Table Creation

Image1.jpg

Table Data
t
Image2.jpg

Now let's move to the code.

Register.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs"Inherits="Login_role.Register" %>

<!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>Register</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table align="center">
            <tr>
                <td colspan="2">
                    <h3>
                         Registration using Role</h3>
                </td>
            </tr>
            <tr>
                <td>
                   
                 <asp:Label ID="Label1" runat="server" Text="UserName:" Font-Bold="True" Width="100px"BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
                    </td>
                <td>
                    <asp:TextBox ID="txt_UserName" runat="server" Width="150px"></asp:TextBox>
                </td>
                <td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter UserName" ControlToValidate="txt_UserName"></asp:RequiredFieldValidator> </td>
            </tr>
            <tr>
                <td>
                  
                 <asp:Label ID="Label2" runat="server" Text="Password:" Font-Bold="True" Width="100px"BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
                 </td>
                <td>
                    <asp:TextBox ID="txt_Password"  TextMode="Password" runat="server"
                        Width="150px"></asp:TextBox>
                </td>
                <td><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Enter Password" ControlToValidate="txt_Password"></asp:RequiredFieldValidator> </td>
            </tr>
            <tr>
                <td>
                <asp:Label ID="Label3" runat="server" Text="Role:" Font-Bold="True" Width="100px"  Height="100px"BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
                    </td>
                <td>
                    <asp:RadioButtonList ID="rbtRole" runat="server" RepeatDirection="Vertical">
                        <asp:ListItem>Admin</asp:ListItem>
                        <asp:ListItem>FreeUser</asp:ListItem>
                         <asp:ListItem>PaidUser</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
                <td><asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Select role" ControlToValidate="rbtRole"></asp:RequiredFieldValidator> </td>
            </tr>
            <tr>
            <td></td>
                <td>
                    <asp:Button ID="btn_register" runat="server" BackColor="#CCFF99" Text="Register"
                        onclick="btn_register_Click" />

                </td>
                <td><asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Login.aspx"
                        ForeColor="#663300">Click here to Login</asp:HyperLink></td>
               
            </tr>
            <tr>
                <td align="center"  colspan="2">
                    <asp:Label ID="lblmsg" runat="server"></asp:Label>
                </td>
            </tr>
        </table>
       
    </div>
    </form>
</body>
</html>

Register.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;
using System.Data.SqlClient;
namespace Login_role
{
    public partial class Register : System.Web.UI.Page
    {

        string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlCommand com;

        protected void btn_register_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(strConnString);
            com = new SqlCommand();
            com.Connection = con;
            com.CommandType = CommandType.Text;
            com.CommandText = "Insert into Login values(@UserName,@Password,@Role)";
            com.Parameters.Clear();
            com.Parameters.AddWithValue("@UserName", txt_UserName.Text);
            com.Parameters.AddWithValue("@Password", txt_Password.Text);
            com.Parameters.AddWithValue("@Role", rbtRole.SelectedValue);
            if (con.State == ConnectionState.Closed)
            con.Open();
            com.ExecuteNonQuery();
            con.Close();
            lblmsg.Text = "Successfully Registered!!!";
            clear();
        }
        private void clear()
        {
            txt_UserName.Text = "";
            rbtRole.ClearSelection();
        }
    }
}

Login.aspx
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Login_role.Login" %>

<!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>Login</title>
    <script type="text/javascript" language="javascript">
    function Validate()
    {
    var UName=document.getElementById('TextBox_user_name');
    var Password=document.getElementById('TextBox_password');
    if((UName.value=='') || (Password.value==''))
    {
     alert('UserName or Password should not be blank');
     return false;
    }
    else
    {
      return true;
    }
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="lb1" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Label><br />
     <asp:Label ID="Label1" runat="server" Text="Name" Font-Bold="True" Width="100px" BackColor="#FFFF66"ForeColor="#FF3300"></asp:Label>
           
        <asp:TextBox ID="TextBox_user_name" runat="server" ForeColor="#993300" Width="100px"></asp:TextBox><br />
        <asp:Label ID="Label2" runat="server" Text="Password" Font-Bold="True" Width="100px"BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
           
        <asp:TextBox ID="TextBox_password" runat="server" ForeColor="#CC6600" TextMode="Password"Width="100px"></asp:TextBox><br />
               
        <asp:Button ID="btn_login" runat="server" Text="Login" Font-Bold="True"
            BackColor="#CCFF99"   OnClientClick="Validate()" onclick="btn_login_Click"
            /><br />
    </div>
    </form>
</body>
</html>

Login.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;
using System.Data.SqlClient;
namespace Login_role
{
    public partial class Login : System.Web.UI.Page
    {
        string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        string str, UserName, Password;
        SqlCommand com;
        SqlDataAdapter sqlda;
        DataTable dt;
        int RowCount;

        protected void btn_login_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(strConnString);
            con.Open();
            str = "Select * from Login";
            com = new SqlCommand(str);
            sqlda = new SqlDataAdapter(com.CommandText, con);
            dt = new DataTable();
            sqlda.Fill(dt);
            RowCount = dt.Rows.Count;
            for (int i = 0; i < RowCount; i++)
            {
                UserName = dt.Rows[i]["UserName"].ToString();
                Password = dt.Rows[i]["Password"].ToString();
                if (UserName == TextBox_user_name.Text && Password == TextBox_password.Text)
                {
                    Session["UserName"] = UserName;
                    if (dt.Rows[i]["Role"].ToString() == "Admin")
                        Response.Redirect("~/Admin/Admin.aspx");
                    else if (dt.Rows[i]["Role"].ToString() == "FreeUser")
                        Response.Redirect("~/FreeUser/FreeUser.aspx");
                    else if (dt.Rows[i]["Role"].ToString() == "PaidUser")
                        Response.Redirect("~/PaidUser/PaidUser.aspx");
                }
                else
                {
                    lb1.Text = "Invalid User Name or Password! Please try again!";
                }
            }
       
        }
    }
}

Admin.aspx
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="Login_role.clerk" %>

<!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>Admin</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <h1><font color="red">Admin Page</font></h1>
    <asp:Label ID="lb1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

Admin.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;

namespace Login_role
{
    public partial class clerk : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lb1.Text = "<b><font color=Brown>" + "WELLCOME ADMIN:: " + "</font>" + "<b><font color=red>" + Session["UserName"] + "</font>";
        }
    }
}

FreeUser.aspx
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FreeUser.aspx.cs" Inherits="Login_role.doctor"%>

<!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>FreeUser</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1><font color="green">FreeUser Page</font></h1>
    <asp:Label ID="lb1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

FreeUser.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;

namespace Login_role
{
    public partial class doctor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lb1.Text = "<b><font color=Brown>" + "WELLCOME FREE USER:: " + "</font>" + "<b><font color=red>" + Session["UserName"] + "</font>";
        }
    }
}

PaidUser.aspx
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PaidUser.aspx.cs"Inherits="Login_role.PaidUser" %>

<!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>PaidUser</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1><font color="olive">PaidUser Page</font></h1>
    <asp:Label ID="lb1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

PaidUser.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;

namespace Login_role
{
    public partial class PaidUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lb1.Text = "<b><font color=Brown>" + "WELLCOME PAID USER:: " + "</font>" + "<b><font color=red>" + Session["UserName"] + "</font>";
        }
    }
}