T
Tony Johansson
I have a html control of type submit which has runat=server making it a html
server control.
I have an event handler on the client and on the server for the same html
server control as you can see below.
It works perfect if I use the code below.
Now to my question if I just replace the statement in the client event
handler with
this statement document.write('Now event handler on client is called');
insted of
this statement alert('hello from the client'); then
the event handler on the server will not be called.
Can somebody explain why ?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
<!--
function Submit1_onclick()
{
alert('hello from the client');
}
// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Submit1" runat="server" style="z-index: 103; left: 0px;
position: absolute; top: 0px"
type="submit" value="submit" onclick="return Submit1_onclick();"
onserverclick="Submit1_ServerClick" />
</div>
</form>
</body>
</html>
//Here is the code-behind file
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void Submit1_ServerClick(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "test", "alert('Hello from
the server');", true);
}
}
//Tony
server control.
I have an event handler on the client and on the server for the same html
server control as you can see below.
It works perfect if I use the code below.
Now to my question if I just replace the statement in the client event
handler with
this statement document.write('Now event handler on client is called');
insted of
this statement alert('hello from the client'); then
the event handler on the server will not be called.
Can somebody explain why ?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
<!--
function Submit1_onclick()
{
alert('hello from the client');
}
// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Submit1" runat="server" style="z-index: 103; left: 0px;
position: absolute; top: 0px"
type="submit" value="submit" onclick="return Submit1_onclick();"
onserverclick="Submit1_ServerClick" />
</div>
</form>
</body>
</html>
//Here is the code-behind file
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void Submit1_ServerClick(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "test", "alert('Hello from
the server');", true);
}
}
//Tony