Free Jobs
Reference




Dot Net Forums: ASPNET (77) C#.NET (39) VB.NET (8) AJAX (21) Silver Light (1) WCF (10) WPF (1) WWF (1) .NET 3.5 (3) SQL SERVER (38) Other (3)

Topic: How to create Login Logout functionality using Ajax Model Popup Extender

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share





User: dhiraj5079 Post Date: 07 Jun 2011 06:58

Introduction:
Creating Login logout functionality using Ajax Model Popup Extender gives better
look and feel to your web site



Main Content:

it can be done as below:


<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>




        

<asp:UpdatePanel ID="UpdatePanelLogin" runat="server">


<contentTemplate>

                 

<ajax:ModalPopupExtender ID="ModalPopupExtenderLogin" runat="server" TargetControlID="LoginImage"

           BackgroundCssClass="modalBackground" CancelControlID="ImageButtonCloseShowPopUp" PopupControlID="PanelLogin" Enabled="true">

 </ajax:ModalPopupExtender>

        

         

 <asp:Panel ID="PanelLogin" runat="server" cssClass="modalPopup" Width="400px" Style="display: none; padding-left: 0px; width: 320px"> 

             <div>

    <div style="font:bold;float:left;width:70px;text-align:center; color:Maroon;color:White;background-color:Maroon;font-size:12px;font-


weight:bold;margin-left:2px;">WOI Login</div>

    <div style="text-align:right;float:right;width:50px;">

     <asp:LinkButton ID="ImageButtonCloseShowPopUp" ToolTip="Close" Height="14" CausesValidation="false" runat="server"

 

 BackColor="maroon" Text="Close" ForeColor="White" Font-Names="Verdana" Font-Size="12px" Font-Bold="true"  />                            

    </div>


    <div style="padding-left:100px;">

    <asp:Label ID="LabelMessage" runat="server" Text="" Font-Size="10" ForeColor="maroon"></asp:Label>

    <br /><br />

    <asp:Label ID="LblUName" runat="server" Text="User name" Font-Size="10"></asp:Label>

        <asp:RequiredFieldValidator ID="RequiredValidatorUsername" runat="server" ControlToValidate="txtUName"


ErrorMessage="*"></asp:RequiredFieldValidator>

    <asp:TextBox ID="txtUName" runat="server" Width="155px" ></asp:TextBox><br /><br />

     &nbsp;<asp:Label ID="LblPassword" runat="server" Text="Password" Font-Size="10"></asp:Label>

      <asp:RequiredFieldValidator ID="RequiredValidatorPassword" runat="server" ControlToValidate="txtPassword"


ErrorMessage="*"></asp:RequiredFieldValidator>

    <asp:TextBox ID="txtPassword" runat="server" TextMode="password" Width="155px"></asp:TextBox>

  

    <br /><br />

    <div style="padding-left:0px;">

    <asp:ImageButton ID="BtnLogin" runat="server" Width="50" Height="26" ImageUrl="images/login.gif" OnClick="BtnLogin_Click" />

       

    </div>   

    </div>   

    </div>

         </asp:Panel>





 <a style="cursor:hand;"><img id="LoginImage" runat="server"  src="images/login.gif" width="47" height="24" alt="Login"  /></a>


in the .aspx.cs page write :


protected void BtnLogin_Click(object sender, EventArgs e)

    {

        DataSet dsUsers = new DataSet("dsUsers");

        DataTable dtUsers = new DataTable("dtUsers");

        dtUsers.Columns.Add("Username", typeof(string));

        dtUsers.Columns.Add("Password", typeof(string));


        dsUsers.Tables.Add(dtUsers);


        DataRow newRow1 = dsUsers.Tables["dtUsers"].NewRow();

        newRow1["Username"] = "user1";

        newRow1["Password"] = "password1";

        dsUsers.Tables["dtUsers"].Rows.Add(newRow1);


        DataRow newRow2 = dsUsers.Tables["dtUsers"].NewRow();

        newRow2["Username"] = "user2";

        newRow2["Password"] = "password2";

        dsUsers.Tables["dtUsers"].Rows.Add(newRow2);


        DataRow newRow3 = dsUsers.Tables["dtUsers"].NewRow();

        newRow3["Username"] = "user3";

        newRow3["Password"] = "password3";

        dsUsers.Tables["dtUsers"].Rows.Add(newRow3);


        //DataList1.DataSource = dsUsers;

        //DataList1.DataBind();

        bool authenticated = false;


        for (int i = 0; i < dsUsers.Tables[0].Rows.Count; i++)

        {

            if (dsUsers.Tables[0].Rows[i]["Username"].ToString().Trim().ToLower() ==

             txtUName.Text.ToLower().Trim().ToString() && dsUsers.Tables[0].Rows[i]["Password"].ToString()

           == txtPassword.Text.Trim())

            {

                authenticated = true;

            }

        }


        if (authenticated == true)

        {

            Session["LoggedIn"] = "true";

            Session["Username"] = txtUName.Text;

           

            Response.Redirect("Default.aspx");

           

        }

        else

        {

           

            PanelLogin.Visible = true;

            LabelMessage.Text = "Invalid Username or Password";

            

            ModalPopupExtenderLogin.Show();

          

        }

       

    }


protected void ImgBtnLogOut_Click(object sender, ImageClickEventArgs e)

    {

        Session["LoggedIn"] = null;

        Session["Username"] = null;

        Response.Redirect("Default.aspx");

    }






Conclusion:
Thus we can create login logout functionality using ModelPopup extender



About Writer:
Hi,I am IT Professional From Mumbai


Writer's Link: http://

Writer's Email:







Comments:
Post Comment





Similar Articles Top ArticlesLatest Articles Other Articles by this Author







www.freejobsreference.com Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)