T
Tony Johansson
Hello!
I just trying to learn how asp.net is handling html server control.
Normally I have used webbserver control here.
In this example I have dragged a html input button into the page see below.
I have then created an event handling method on the client named
Button1_onclick.
Then I added runat="server" making the ASP.NET to look for control if it
need
any server-side processing.
As the last thing I added an event handler for the html server control in
the code-behind file.
Now to my question when I now run the page and hit the button
no event handler is called. But two event handler should have been called
the one on the client which is called Button1_onclick and the one on the
server
which is called Button1_ServerClick.
So is it not possible do do what I have done here ?
<%@ 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 language="javascript" type="text/javascript">
<!--
function Button1_onclick()
{
document.write('Now event handler on client is called');
}
// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" runat="server" style="z-index: 102; left: 116px;
position: absolute; top: 368px"
type="button" value="button" language="javascript"
onclick="return Button1_onclick()" onserverclick="Button1_ServerClick" />
</div>
</form>
</body>
</html>
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 Button1_ServerClick(object sender, EventArgs e)
{
Response.Write("Now event handler on server is called");
}
}
//Tony
I just trying to learn how asp.net is handling html server control.
Normally I have used webbserver control here.
In this example I have dragged a html input button into the page see below.
I have then created an event handling method on the client named
Button1_onclick.
Then I added runat="server" making the ASP.NET to look for control if it
need
any server-side processing.
As the last thing I added an event handler for the html server control in
the code-behind file.
Now to my question when I now run the page and hit the button
no event handler is called. But two event handler should have been called
the one on the client which is called Button1_onclick and the one on the
server
which is called Button1_ServerClick.
So is it not possible do do what I have done here ?
<%@ 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 language="javascript" type="text/javascript">
<!--
function Button1_onclick()
{
document.write('Now event handler on client is called');
}
// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" runat="server" style="z-index: 102; left: 116px;
position: absolute; top: 368px"
type="button" value="button" language="javascript"
onclick="return Button1_onclick()" onserverclick="Button1_ServerClick" />
</div>
</form>
</body>
</html>
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 Button1_ServerClick(object sender, EventArgs e)
{
Response.Write("Now event handler on server is called");
}
}
//Tony