Archive for October, 2009

Get Current Page Name using javascript

October 30, 2009 1 comment

The below function will give you the current page name by using javascript:

function GetCurrentPageName() {
//method to get Current page name from url.
//return page name in small .
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf(‘/’) + 1);
return sPage.toLowerCase()

now when using :


function OnLoad() {

if (GetCurrentPageName() == ‘home.aspx’) {

alert(‘i got current page name’);


Calling Javascript From Codebehind in .aspx.cs

October 26, 2009 Leave a comment

Many times we need to invoke javascript function in codebehind of page ie. in .aspx.cs page.

There are many ways to accomplish this.

I will provide you a link which will show you how to invoke javascript in master and content page of

Other ways are as follows:

in .aspx.cs write following code:

Page.ClientScript.RegisterStartupScript(this.GetType(), “alert”, “Disconnect();”, true);

in .aspx write following code:

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

function Disconnect()
alert(‘Sucessfully Disconnected’);



Other way is:

Response.Write(“<script>alert(Successfully Disconnected”)</script>”);

Refer another good article at :

Open a New Window On Server Side using Javascript Code in

October 24, 2009 1 comment

Normally to open a new window using javascript we write the following code:

// open new window with specified path

function OpenWindow(url)

    newwindow =, 'mywindow', 'width=500,height=400');  


Now In .aspx.cs page or server side to use the javascript window open you have to use the following code

 StringBuilder popupScript = new StringBuilder();
 popupScript.Append("<script language='JavaScript'>'ViewReports.aspx?groupid=" + ddlreportGroup.SelectedValue.ToString() + "&FromDate=" + Convert.ToDateTime(txtDate.Text) + "&Todate=" + Convert.ToDateTime(txtToDate.Text) + "&Report=Rptname" + "', '', 'width=950, height=580,scrollbars,status,menubar=no,resizable,toolbar=no,titlebar=no,location=no');</script>");
// if you are using script manager - update panel then this
 ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "PopupScript", popupScript.ToString(), false);
Page.RegisterStartupScript("PopupScript", popupScript.ToString());

Add “Select” Option To Dropdown list in

October 23, 2009 Leave a comment

There are many ways to add select option to dropdown list.. Here in this post i will list some of the ways:


<asp:DropDownList ID=”ddltemp" runat=”server”>
<asp:ListItem Value=”0">Select</asp:ListItem>


ddltemp.Items.Add(new ListItem(”Select”, “0"));


ddltemp.Items.Insert(0, new ListItem(”Select”, “0"));


ddltemp.Items.Insert(0, "–Select–");
ddltemp.Items[0].Value = "0";