Thursday, December 3, 2009

IIS 7.0 HTTP Error Pages AND The HTTP status codes in IIS 7.0

IIS 7.0 HTTP Error Pages

http://blogs.msdn.com/webtopics/archive/2008/05/28/iis-7-0-http-error-pages.aspx

The HTTP status codes in IIS 7.0

http://support.microsoft.com/kb/943891

Auto Refresh

Method 1: Response.AddHeader

To Refresh Web page After every 5 Seconds You can add following code,

Response.AddHeader("Refresh", "5");

Cricket Sites, Stock Exchange sites use similar logic :)

Method 2: In body Tag, window.setTimeout

The 1000 = 1 Second...

<body onload="window.setTimeout('window.location.reload()',1000);">

Method 3: In Meta Tag

Theres also a meta tag that you can define on the head, but not sure wheter it refreshes even if the content has not finished loading or if it starts counting when the head section loaded. Code would be something like that:

<meta content="600" http-equiv="refresh">

Method 4: Timer Control : Microsoft ASP.NET 2.0 AJAX Extensions server control

In following example, the timer interval is set to 10 seconds

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Timer Example Page</title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
OriginalTime.Text = DateTime.Now.ToLongTimeString();
}

protected void Timer1_Tick(object sender, EventArgs e)
{
StockPrice.Text = GetStockPrice();
TimeOfPrice.Text = DateTime.Now.ToLongTimeString();
}

private string GetStockPrice()
{
double randomStockPrice = 50 + new Random().NextDouble();
return randomStockPrice.ToString("C");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000" />

<asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
Stock price is <asp:Label id="StockPrice" runat="server"></asp:Label><BR />
as of <asp:Label id="TimeOfPrice" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<div>
Page originally created at <asp:Label ID="OriginalTime" runat="server"></asp:Label>
</div>
</form>
</body>
</html>

Tuesday, December 1, 2009

Generating Sequence Number in DataGrid with Paging

There are two ways you can generate sequence number in grid.


1. Generate Sequence Number in Datagrid from aspx page you can simply add:

<%# (DataGrid1.PageSize*DataGrid1.CurrentPageIndex)+ Container.ItemIndex+1%>


2. Generate Sequence Number in Datagrid from SQL:

SELECT ROW_NUMBER() OVER(ORDER BY ID DESC) AS SeqNumber FROM TABLE_NAME

AND Bind DataGrid as,

<%#DataBinder.Eval(Container.DataItem,"SeqNumber")%>

Use for loop in DOS

Example 1.

Register All dlls containing in folder:

Suppose you want to register 100 dlls containg in folder C:\dlls then goto command prompt

SOLUTION:
goto c:\dlls and write command below
for %i in (*.dll) do RegSvr32 -s %i

Example 2.

Print all files containg in folder

SOLUTION:
for %i in (*.*) do echo %i