I don't think you should set the PostBackUrl property on that linkbutton. I think you should just use the onclick property to call your javascript function. PostBackUrl probably screws with the whole web form because it's intended purpose is to post the whole form back to another URL.
I only modified one line:
Code:
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LinkButton1.Text = "Time: " + System.DateTime.Now.ToLongTimeString();
//LinkButton2.PostBackUrl = "javascript:SayHello();";
LinkButton2.Attributes.Add("onclick", "SayHello()");
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton1.Text = "Time: " + System.DateTime.Now.ToLongTimeString();
}
</script>
<html>
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function SayHello()
{
alert("Hello");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server">Say Hello</asp:LinkButton>
</div>
</form>
</body>
</html>
Neil Timmerman
Programmer
Veris Consulting