Monday, 9 June 2014

Restrict multiple login of a single user in asp.net using cache


//On Master Page

protected void Page_Init(object sender, EventArgs e)
    {
        Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
    }


protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetAllowResponseInBrowserHistory(false);
        Request.Browser.Adapters.Clear();
       
}

Globly- Login Page

 public System.Data.DataTable dtSessionGlobal = new DataTable();

//On Page Load

 protected void Page_Load(object sender, EventArgs e)
    {      

        if (Cache["UserSessions"] != null)
        {
            dtSessionGlobal = (DataTable)Cache["UserSessions"];
            if (dtSessionGlobal.Columns.Count == 0)
            {
                dtSessionGlobal.Columns.Add("UserName");
                dtSessionGlobal.Columns.Add("SessionID");
            }
        }
        else
        {
            dtSessionGlobal.Columns.Add("UserName");
            dtSessionGlobal.Columns.Add("SessionID");
            Cache["UserSessions"] = dtSessionGlobal;
        }
}

//On All Page Load Event

 protected void Page_Load(object sender, EventArgs e)
    {
        
        DataTable dtSessionGlobal = new DataTable();
        if (Cache["UserSessions"] != null)
        {
            dtSessionGlobal = (DataTable)Cache["UserSessions"];
        }
        if (Session["username"] == null)
        {
            Response.Redirect("~/SignIn Users", false);
        }
        
        if (!IsPostBack)
        {
            if (dtSessionGlobal.Rows.Count > 0)
            {
                System.Data.DataRow[] dr = dtSessionGlobal.Select(" UserName='" + Session["UName"] + "' AND SessionID<>'" + Session.SessionID + "'");
                if (dr.Length > 0)
                {
                    Response.Redirect("~/SignIn Users");
                }
                else if (dtSessionGlobal.Select(" UserName='" + Session["UName"] + "'").Length == 0)
                {
                    Response.Redirect("~/SignIn Users");
                }
            }
}

Sunday, 8 June 2014

Open new tab in asp.net code behind

//HTML

<asp:Button ID="Button1" runat="server" Text="Button" 
onclick="Button1_Click" 
OnClientClick ="document.forms[0].target = '_blank';" />



//Code Behind


protected void Button1_Click(object sender, EventArgs e)
    {
        string newtabl = @"~/FrmNewContent.aspx";
        Response.Redirect(newtabl);       
    }

Saturday, 7 June 2014

Get Control id using jquery


//id with control id

$('#<%=Controlid.ClientID%>').attr('id')

//Id with Class Name

$('.ButtonClass').attr('id');

Thursday, 5 June 2014

Count Number of columns in a table using javascript or jquery


//HTML

<table id="table1">
<tr>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
</tr>
<tr>
</table>
cells
<script>
alert(document.getElementById('table1').rows[0].cells.length)
</script>

//Jquery

 <script type="text/javascript">
       $(document).ready(function () {
              alert($(Table).find('tr')[0].cells.length);
         

       });  
   </script>

Monday, 2 June 2014

Direct insert and create table from Sql server Query-

//Sql Query-

Select * into TableNameA From TableNameB

Add CSS in gridview cells using jquery in asp.net

//HTML -GridView

 <asp:GridView ID="GridView1" runat="server" >
        </asp:GridView>

//Jquery-

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

 <script type="text/javascript" language="javascript">

    $(document).ready(function () {
        $(function () {
            $('#<%=GridView1.ClientID%> td').toggle(function () {
                $(this).css('background', '#93BD00');

            },
                function () {
                    $(this).css('background', 'white', 'cursor', 'pointer', 'padding', '2px');
                });
        });
 </script>

Check and Uncheck all Checkboxlist using javascript in asp.net

///HTML

<asp:CheckBoxList ID="CheckBoxList1" RepeatDirection="Vertical" runat="server" onclick="javascript: changeSelectAll ()">
                    </asp:CheckBoxList>

<asp:CheckBox ID="CheckBox1" runat="server" onclick="javascript: CheckBoxListSelect (this.id)" />  


//CheckBoxList function

function CheckBoxListSelect(chkid, chblid) {
       var chkBoxList = document.getElementById('<%= CheckBoxList1.ClientID %>');
       var chkB = document.getElementById(chkid);
       if (chkB.checked) {
           var chkBoxCount = chkBoxList.getElementsByTagName("input");
           for (var i = 0; i < chkBoxCount.length; i++) {
               chkBoxCount[i].checked = true;
           }
       }
       if (!chkB.checked) {
           var chkBoxCount = chkBoxList.getElementsByTagName("input");
           for (var i = 0; i < chkBoxCount.length; i++) {
               chkBoxCount[i].checked = false;
           }
       }

       return false;
   }


//CheckBoxList function


   function changeSelectAll() {
       var chkBoxList = document.getElementById('<%= CheckBoxList1.ClientID %>');
       var chkb = document.getElementById('<%= CheckBox1.ClientID %>')
       var chekb = true;
       var chkBoxCount = chkBoxList.getElementsByTagName("input");
       for (var i = 0; i < chkBoxCount.length; i++) {
           if (!chkBoxCount[i].checked) {
               chekb = false;
               break;
           }
       }
       if (chekb) { chkb.checked = true; } else { chkb.checked = false; }
       return false;
   }

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...