2012-05-29 59 views
0

如何從asp.net代碼中傳遞this.href?以下是我擁有的,在JavaScript中我加了警惕,價值和它說「未定義」Javascript this.href從後面的asp.net代碼

Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript(this.href);", true); 

function Callscript(href) 
{ 
    alert(href); 
} 

回答

2

href不是全局對象的屬性。我相信你正在尋找window.location.href

Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript(window.location.href);", true); 
0

你是不是傳遞HREF從aspx.cs文件正確。它應該是下面的東西。

Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript('" + this.href + "');", true); 

function Callscript(href) 
{  
    alert(href); 
} 

希望這有助於!

+0

這是錯的! this.href不是一個頁面屬性.. – CoolArchTek

0

「這」是兩個不同的東西 - 它是一個在服務器上,另一個在客戶端上。

您可以嘗試修改你的啓動腳本,像這樣:

Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript('" + this.href + "');", true); 
相關問題