Thursday, July 14, 2011

ASP.NET Best Practices for High Performance in your Applications!!


I found some great articles on Best pracites and improving the performance of ASP.NET application. Check out these great articles.
Practice Article 1
Practice Article 2
Practice Article 3

How to display your own logo in the address bar?

If you need to put your website logo in the top address bar instead of browser's logo then follow these steps.
1. Add a file called "favicon.ico" (an icon file of your website logo) to your website root directory.
2.Insert the following HTML tag inside the <head> ... </head> section of your web page.
<link rel="shortcut icon" href="favicon.ico" >

**If you are working with master pages then put this code in head section of master page otherwise you have to put this code in every page.

Asp.net Articles..Refer it.

I found a great post, which focuses on ASP.NET Coding Standards. These standards should be considered while working with ASP.NET application.

You can read the article Click here.

15 New Features of jQuery 1.4 download below link..


jQuery 1.4 was recently released. There are many new features, enhancements and performance improvements included in 1.4!
You can download jQuery 1.4 right now, here:http://code.jquery.com/jquery-1.4.js
Check this article to know 15 New Features of JQuery 1.4




Thanks,
s.c

Get list of all currently running procedure in SQL Server..

Sometimes it is a need to find out which stored procedure are running on the SQL Server.Below SQL query will provide the list of stored procedure which are currently running on the server.

1
2
3
4
5
6
7
SELECT OBJECT_NAME(ObjectID) as ObjectName,
  st.Text,
  DB_NAME(database_ID) as dbname,
  Blocking_session_ID as BlockingSessionID, 
  *
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS st

Retrieve Table Name from all the Procedures of any database..

In Sql Server 2000 or later versions,

Suppose you have deleted one of the column of any table and now you have to change all your procedures where this column is used.

1. One way is to open every procedure and look for the table and the cloumn name.

2. Second solution is the

Select * from information_Schema.Routines where Routine_Definition like '%table1%'

This Query will allow to find out whether table name specified in where conditoin exists in which Procedures.

INFORMATION_SCHEMA.ROUTINES view is used to retrieve information about stored procedures. This view contains one row for each stored procedure accessible to the current user in the current database.

The INFORMATION_SCHEMA.ROUTINES view was introduced in SQL Server 2000. This view is based on the sysobjects, syscomments and other system tables.

Count number of tables in a SQL Server database..

A simple query to find out number of tables in database is

USE SLINGKAST
SELECT COUNT(*) from information_schema.tables 
WHERE table_type = 'base table'

It's only couting the character to enter the textbox inasp.net

<script type="text/javascript">
    function Count(x) {
        document.getElementById("Label1").innerHTML = document.getElementById("TextBox2").value.length;
    }
</script>
<asp:TextBox ID="TextBox2" runat="server" Height="78px"
TextMode="MultiLine" Width="224px" onkeyup="Count(this.length)"
MaxLength="5" ViewStateMode="Enabled"></asp:TextBox>

Coundown text (Multiline) left from Textbox in asp.net

Source page:
=========
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="textboxcountdown.aspx.cs" Inherits="textboxcountdown" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
    function textCounter(field, countfield, maxlimit) {
        var MaxLength = 100;
        var Label1 = document.getElementById(countfield);
        if (field.value.length > maxlimit)
            field.value = field.value.substring(0, maxlimit);
        Label1.innerText = (maxlimit - field.value.length) + ' Characters Remaining';
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server" Height="128px" MaxLength="1000"
            TextMode="MultiLine" Width="313px" ></asp:TextBox><br />
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>
Code behindWindow:
===============
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class textboxcountdown : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
     TextBox1.Attributes.Add("onkeydown", "textCounter(this,'" + Label1.ClientID + "', 100)");
    TextBox1.Attributes.Add("onkeyup", "textCounter(this,'" + Label1.ClientID + "', 100)");
    TextBox1.Attributes.Add("onmousedown", "textCounter(this,'" + Label1.ClientID + "', 100)");
    TextBox1.Attributes.Add("onmouseup", "textCounter(this,'" + Label1.ClientID + "', 100)");
    TextBox1.Attributes.Add("onblur", "textCounter(this,'" + Label1.ClientID + "', 100)");
    }

}

Javascript, only numbers textbox, not allow copy/paste to it.

<asp:textbox id="TextBox1" oncopy="return false;" onpaste="return false;" runat="server"></asp:textbox>
Note that I attached event handlers to the element in the HTML declaration. This will work, but will produce a compiler warning. The proper way to do this for a server control is in the Page_Load handler of the server-side code like this:
 TextBox1.Attributes.Add("oncopy", "return false;");
 TextBox1.Attributes.Add("onpaste", "return false;");

-----------------------
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCodeif (charCode > 31 && (charCode < 48 || charCode > 57)) {

return false;
document.getElementById("charCode").value = ""; }
else
{
return true; }
}
mytextbox.Attributes.Add("onkeypress", "JavaScript:return isNumberKey(event);");

how to limit the number characters length in Multiline textbox using asp.net

Introduction:

Here I will explain how to limit the number of characters length in Multilne textbox and how to remove vertical scrollbar in Multiline textbox using asp.net

Description:

One day I found one interesting thing in one of the sms sending site in that they provide one message textbox that is allowing only 140 characters to send message and they are displaying number characters left in the messagebox to type and if we are typing text in messagebox they are displaying the percentage graph also how much percentage of characters has entered in message textbox out of 140 characters. At that time I decided to write the post based on that here I designed page with one textbox that has a multiline property and one label to display the number of characters left to type in textbox and used tables to display the percentage graphs based on text typed in textbox

 First design your aspx page like this


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Limit the number of characters in multiline textbox</title>
<script type="text/javascript">
//This function is used to display the number of characters left and percentage graph
function CharactersCount() {
var CharLength = '<%=txtMessage.MaxLength %>';
var txtMsg = document.getElementById('txtMessage');
var lblCount = document.getElementById('lblChar');
var colorwidth = txtMsg.value.length;
var divcolor = document.getElementById('Colordiv');
if (txtMsg.value.length > CharLength) {
txtMsg.value = txtMsg.value.substring(0, CharLength);
}
lblCount.innerHTML = CharLength - txtMsg.value.length ;
if (colorwidth >= 1) {
divcolor.width = (colorwidth * 1.05) + "px";
divcolor.bgColor = 'red';
divcolor.height = 6 + "px";
}
else {
divcolor.width = 1 + "px";
divcolor.bgColor = '#9ED40A';
}
}
</script>
<style type="text/css">
.style1
{
width: 65%;
}
.lblstyle
{
background-color:#E2EEF1;
color:Red;
font-weight:bold;  
font-size: 14px;
font-family: Tahoma;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td class="style1">
</td>
<td>
<span style=" font-family:Verdana; font-size:12px">Left:</span>
<asp:Label ID="lblChar" runat="server" Text="100" CssClass="lblstyle"></asp:Label>
</td>
</tr>
<tr>
<td class="style1"></td>
<td style="width:105px">
<table cellpadding="0" cellspacing="0" width="100%">
<tr style="background-color:#9ED40A; height:6px">
<td>
<div>
<table cellpadding="0" cellspacing="0">
<tr style="height:6px">
<td id="Colordiv" runat="server">
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="txtMessage" onkeyup="Javascript:CharactersCount();" runat="server" Style="overflow: hidden;" Height="80px" TextMode="MultiLine" Width="300px" MaxLength="100" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
If you observe above code I applied TextMode="MultiLine" property for textbox it give a chance to allow user to enter more text and I applied Style="overflow: hidden;" property for textbox by using this property we can remove vertical scrollbar for multiline textbox. Now if you observe header part I written javascript function to limit the number of characters length in Multiline textbox and displaying percentage graph including number of remaining characters left to type in textbox. In JavaScript I used MaxLength property to get the MaxLength of characters and used substring() function this function is used to extracts the characters from a string, between two specified indices.

Demo

Tuesday, July 12, 2011

Session Concept's

Session:
========
Session provides that facility to store information on servier
memory. it can support any type of object to store along with our
custom object. For every client session data store separetely
means session data is stored as per client basis.

Advantages:
==========
-it helps to maintaing user information and data to all over the applications
-it can easily be implemented and we store any kind of objects or entity\
-Stores every client data information separetely.
-Session is secure and visible from user.

Disadvantages:
==============
- Performance overhead in case of large volume of user, because
of session data stored in server memory itself.
-Overhead involved in serializing and De-serializing session
data. because in case of stateserver and sqlserver session
mode we need to seralize the object before store.

Following code is used for storing a value to session
=====================================================


Storing UserName in Session:
----------------------------

       Session["UserName"] = txtUser.Text;

Now, let see how we can retrieve values from Session


Check weather session variable null or not:
-------------------------------------------

        if (Session["UserName"] != null)
        {
            //Retrieving UserName from Session
            lblWelcome.Text = "Welcome : " + Session["UserName"];
        }
        else
        {
         //Do Something else
        }