Breaking News

Editors Picks

Friday, February 25, 2011

'Remember Me' option in ASp.net


'Remember Me' option in ASp.net



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

namespace WebApplication1
{
    public partial class WebForm4 : System.Web.UI.Page
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Cookies["myCookie"] != null)
                {
                    HttpCookie cookie = Request.Cookies.Get("myCookie");
                    txtUserName.Text = cookie.Values["username"];
                    txtPassword.Text = cookie.Values["password"];
                }
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                objImpl = new mymethod();
                bool IsAvailable = false;
                HttpCookie myCookie = new HttpCookie("myCookie");
                bool IsRemember = chkRememberMe.Checked;

                IsAvailable = objImpl.CheckUserLogin(txtUserName.Text, txtPassword.Text);
                if (IsAvailable)
                {
                    DataTable dtUserName = objImpl.ReadUserIdbyUserName(txtUserName.Text);
                    if (dtUserName != null)
                    {
                        if (dtUserName.Rows.Count == 1)
                        {
                            Session["UserId"] = dtUserName.Rows[0].ItemArray[0].ToString();
                        }
                    }
                    if (IsRemember)
                    {
                        myCookie.Values.Add("username", txtUserName.Text);
                        myCookie.Values.Add("password", txtPassword.Text);
                        myCookie.Expires = DateTime.Now.AddDays(15);
                    }
                    else
                    {
                        myCookie.Values.Add("username", string.Empty);
                        myCookie.Values.Add("password", string.Empty);
                        myCookie.Expires = DateTime.Now.AddMinutes(5);
                    }
                    Response.Cookies.Add(myCookie);
                    //FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, chkRememberMe.Checked);
                    Response.Redirect("dashboard.aspx");
                }
                else
                {
                    lblError.Text = "Invalid UserName or Password or else your Username blocked";
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("Default.aspx");
            }
        }
     
    
    }
}

Read more ...

Date format in datagrid


Date format in datagrid




<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
                                                    <tr>
                                                        <td>
                                                            <div style="overflow: auto; height: 400px;">
                                                                <asp:GridView ID="grdViewGroup" AllowPaging="true" runat="server" AutoGenerateColumns="false"
                                                                    PageSize="10" OnPageIndexChanging="grdViewGroup_PageIndexChanging" OnRowCommand="grdViewGroup_RowCommand"
                                                                    OnRowDeleting="grdViewGroup_RowDeleting" OnRowEditing="grdViewGroup_RowEditing">
                                                                    <Columns>
                                                                        
                                                                        <asp:TemplateField HeaderText="Date Created">
                                                                            <ItemTemplate>
                                                                                <asp:Label ID="lblDate" runat="server" Text='<%#Eval("DateCreated","{0: dd/MM/yyyy}") %>'>asp:Label>
                                                                            ItemTemplate>
                                                                            <ItemStyle HorizontalAlign="center" VerticalAlign="Middle" CssClass="border" />
                                                                            <HeaderStyle Width="17%" HorizontalAlign="center" VerticalAlign="Middle" BackColor="#157AC0"
                                                                                CssClass="white_text" />
                                                                        asp:TemplateField>
                                                                       
                                                                        
                                                                    Columns>
                                                                asp:GridView>
                                                               
                                                            div>
                                                        td>
                                                    tr>
                                                table>
Read more ...

Find Controls inside GridView


Find Controls inside GridView



// grid view defination
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="PapayaWhip"  BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" Font-Names="Tahoma" Height="16px"
Width="928px">
<Columns>
<asp:TemplateField>
<HeaderTemplate>HeadingHeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="text_box1" runat="server">asp:TextBox>
ItemTemplate>
asp:TemplateField>
asp:GridView>


//code for accessing value of text_box1 inside the GridView1

  for(int i = 0;i<GridView1.Rows.Count; i++)
  {
    TextBox t1;
    t1 = (TextBox)GridView1.Rows[n].FindControl("text_box1");
    Response.Write(t1.Text);
  }
Read more ...

Trace Mobil number location and Mobile number operator in India


Trace Mobil number location and Mobile number operator in India


Enter 10 Digit Mobile Number:




Mobile Number Details

Read more ...

Contact Us

Name

Email *

Message *