Monday, June 15, 2009

Looping in Enum

C# Code

public
enum Suits
{
Spades,
Hearts,
Clubs,
Diamonds,
NumSuits
}

public void PrintAllSuits()
{
foreach(string name in Enum.GetNames(typeof(Suits)))
{
System.Console.WriteLine(suit);
}
}

Thursday, June 11, 2009

Clear cache to load the page when browser back button is clicked

C# Code

in the Page_load

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();

Using javascript we can disable the browser back event.Whenever user clicks back button it show the previous button and again redirect to current page.

javascript code


function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);

Tuesday, June 2, 2009

Getting active tab index of a tab using Javascript

Javascript File

function SaveActiveTabIndex(sender)
{
var activetabindex = sender.get_activeTab().get_tabIndex();
setCookie(activetabindex);
}

function setCookie(value)
{
document.cookie = "tabIndex=" + escape(value);
}

C# File

Register the tab control with OnClientActiveTabChanged.e.g.

tabProgramInfo.OnClientActiveTabChanged = "SaveActiveTabIndex";

and retrive the active tab index of this tab control from cookie.

int activeTabIndex=Convert.ToInt32(Server.HtmlEncode(Request.Cookies["tabIndex"].Value));