-
Redirect
Suppose i have one label & one button. Suppose labe text is
http://www.dreamincode.net/forums/showforum30.htm
I Want that on button click,my form is redirtected to the above URL using JS.
FIRST METHOD
Code:
protected void Page_Load(object sender, EventArgs e)
{
Button2.Attributes.Add("onclick", "navigated()");
}
<script language ="javascript" type ="text/javascript" >
function navigated()
{
var url=document.getElementById("Label1").value;
alert(url);
}
</script>
SECOND METHOD
Code:
protected void Page_Load(object sender, EventArgs e)
{
Button2.Attributes.Add("onclick", "navigated()");
}
<script language ="javascript" type ="text/javascript" >
function navigated()
{
var url=document.getElementById('<%= Label1.ClientID %>').value;
alert(url);
}
</script>
In both the cases,in url undefined is coming. y SO?
-
Re: Redirect
labels are rendered as span tags, look at the html source in your browser to see this. So you would get the label text using javascript with innerText or innerHtml
document.getElementById("Label_ID").innerText
-
Re: Redirect
Surely if you know what's in the label, you could make the button go directly.
protected void Page_Load(object sender, EventArgs e)
{
Button2.Attributes.Add("onclick", "document.location.href='http://example.com/'"); //Whatever is in your label.
}
-
Re: Redirect
Hey,
Or better, still, why render a button at all. It would seem to me that it would be more intuitive to render the label as a hyperlink instead. No?
Gary
-
Re: Redirect