Javascript in Filename.aspx.cs
Hi Guys,
Anyone here knows how to use Javascript in .aspx.cs.
I have here the code for my Button controls.
Code:
protected void Button1_Click(object sender, EventArgs e)
{
lblMessage.Text = "";
Button1.Attributes.Add("OnClick", "javascript:history.back()");
}
It can't go back to my previous page. :D
Thanks in advance.
Re: Javascript in Filename.aspx.cs
When you click button1, the page posts back. It then adds the onclick attribute to the button. When you then click on the button again, it'll go back one page, but that'll be the page that had the button without the javascript on it.
You should be doing this in the Page Load event and use a button that does not have a postback associated with it.
<input type="button" onclick="javascript:history.back();" value="Back"/>