Posts

Showing posts from February, 2010

How to speed up your web site/application

In my recent experience I have faced some performance issues one of them is web application becomes very much slow. To identify this problem I have searched over the net and I have found a lots of topics.

Now I want to share some of the topics with you in summarized way:

1.Minimize HTTP Requests
2.Use a Content Delivery Network
3.Add an Expires or a Cache-Control Header
4.Gzip Components
5.Put Stylesheets at the Top
6.Put Scripts at the Bottom
7.Avoid CSS Expressions
8.Make JavaScript and CSS External
9.Reduce DNS Lookups
10.Minify JavaScript and CSS
11.Avoid Redirects
12.Remove Duplicate Scripts
13.Configure ETags
14.Make Ajax Cacheable
15.Flush the Buffer Early
16.Use GET for AJAX Requests
17.Post-load Components
18.Preload Components
19.Reduce the Number of DOM Elements
20.Split Components Across Domains
21.Minimize the Number of iframes
22.No 404s
23.Reduce Cookie Size
24.Use Cookie-free Domains for Components
25.Minimize DOM Access
26.Develop Smart Event Handlers
27.Choose over …

Dynamically add control in asp.net

Recently I have faced a problem when try to dynamically add controls in asp.net, like this,
In test.aspx page

<body>
    <form id="form1" runat="server">
    <div>
        <asp:PlaceHolder ID="PlaceHolder1" runat="server" >    </asp:PlaceHolder>

    </div>
    </form>
</body>

In test.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Button btn = new Button();
btn.ID = "btnSave";
this.PlaceHolder1.Controls.Add(btn);
}

Problem:

It is working fine but when I press any button I mean any post back occur It disappears.
After search for a long time I got the proper solution, now I would like to share this with you.

Solution:
To avoid this problem one should dynamically load the controls during Page_Init because we may want to hook up our events with proper handler at an early stage.

protected void Page_Init(object sender, EventArgs e)
{
Button bt…

Use Master page <body> tag in Content page of asp.net

How to use the <body> onclick from content page in asp.net?

Master page is introducing from asp.net 2.0, this is the main layout page for whole application content page just inherit it.

So that,we get the <body> tag only in Master page,in content page there is no body tag. But I need to use this body tag from content page.

After search it I found a solution in asp.net forum. Original link: http://forums.asp.net/t/1062445.aspx

Sample:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" Title="Test Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">

function ClearBox()
{
var divBoxID=document.getElementById('BoxDiv');
divBoxID.style.display='none';
}

document.body.onclick= ClearBox;

</script>
    <…

Converting Single-File Web Forms Pages to Code-Behind Pages

Sometimes I face some problem with single web form(only aspx page no code behind page) page. I am used to work in code-behind page,so that I try to solve this problem in may way but at last I found the solution in msdn. So I want to share this portion of the article with you:

It might be that the only thing you want to do with a single-file Web Forms page in Visual Studio is to convert it to a code-behind Web Forms page. Using Visual Studio to convert a single-file page to a code-behind page automatically accomplishes the following:

1. Generates a code-behind class file for the page.
2. Adds the appropriate page directives to the page so it is linked with the code-behind file.

The conversion does not do the following:

a. Convert inline code to code in the class file.

To convert a single-file .aspx page to code-behind

1. Open an existing project, or create a new ASP.NET Web application.
2. On the Project menu, click Add Existing Item.
3. Browse to the .aspx page that you want to…

Basic Idea on JSON

What is JSON?

JSON is a very lightweight data format based on a subset of the JavaScript syntax, namely array and object literals. JSON allows communicating with server in a standard way. JSON is used as communication notation instead of XML.

JSON objects are typed while XML data is typeless
1.JSON types: string, number, array, boolean,
2.XML data are all string

JSON stands for Javascript Object Notation which is a data structuring format that is extremely clean and lightweight. Even though JSON is native to javascript (as in, it can be turned into an object directly by javascript), it is quite easy to handle with other languages, making it an ideal replacement of XML when javascript is involved with the exchange of data (i.e. ajax).

var fruitColors =
{
"apple":"green",
"banana":"yellow",
"orange":"orange"
};

alert(fruitColors .apple); //outputs "green"
alert(fruitColors .orange); //outputs "orange&q…

Problem using AJAX call in IE6 and IE7

IE6 & IE7 makes problem when use xmlhttprequest for ajax

At first time when I used core ajax using xmlhttprequest. Using this technique we sent parameter as querystring through the url,like this,

function GetEmailId()
{
var url="http://server.com/test.aspx";
url=url+"&sid=test";
xmlhttp.onreadystatechange=statechangedLogin;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
function statechangedLogin()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.responseText=="Login")
{
//write your code
}
}
}
For the first time it is working fine,but when you try to second time in the same browser(IE6) its not work.

This is becuse Internet Explorer will also cache dynamic pages and this is a problem because the URL of the page may not change but the content will.A workaround for this situation can be achieved by adding a unique time stamp or random number, or possibly both, typically using the Date object and/or Math.random() such …

scrollTop not work in IE6

scrollTop problem in IE6
I face a lots of problem ie6.Now I want to share one with you and how to solve it.
Hope that it may helps you.
divObj.scrollTop=0 moves to top of the div but it is not working in IE6.

To solve this you can use:

divObj.scrollTop = divBody.offsetTop; //for scroll to top of the div
divObj.scrollHeight = divBody.offsetHeight; //for scroll to bottom of the div

for more info please visit:
http://radio.javaranch.com/pascarello/2005/12/14/1134573598403.html