Reputation: 3839
How do I pass this.href from asp.net code behind? Here is what I have, and in javascript I added a alert to see the value and it says 'undefined'
Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript(this.href);", true);
function Callscript(href)
{
alert(href);
}
Upvotes: 0
Views: 920
Reputation: 46647
href
is not a property of the global object. i believe you are looking for window.location.href
:
Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript(window.location.href);", true);
Upvotes: 2
Reputation: 5518
"This" is two different things - it's one thing on the server and another on the client.
You may try modifying your startup script like so:
Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript('" + this.href + "');", true);
Upvotes: 0
Reputation: 1449
You are not passing the href from aspx.cs file properly. It should be something like below.
Page.ClientScript.RegisterStartupScript(this.GetType(), "Sample", "Callscript('" + this.href + "');", true);
function Callscript(href)
{
alert(href);
}
Hope this Helps!!
Upvotes: 0