strange problem when using a html server control


T

Tony Johansson

Hello!

Below I have a simple html code where I have dragged a HTML control into the
page.
As you can see below I have specified runat=server for this html control so
it's now a html server control
Now to the strange problem how is it possible that when I click on the
button the event handler on the client is called.
How can that happen when I have specified runat=server. I have thought when
you specified runat=server you can only use
event handler on the server ?

<%@ 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('Hello');
}

// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;
<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()" />

</div>
</form>
</body>
</html>
 
Ad

Advertisements

E

Eliyahu Goldin

What runat=server does is telling ASP.NET to look into the control if it
needs any server-side processing. It won't affect any existing client-side
setting, unless you do it in the code behind..


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://blogs.microsoft.co.il/blogs/egoldin
http://msmvps.com/blogs/egoldin


Tony Johansson said:
Hello!

Below I have a simple html code where I have dragged a HTML control into
the page.
As you can see below I have specified runat=server for this html control
so it's now a html server control
Now to the strange problem how is it possible that when I click on the
button the event handler on the client is called.
How can that happen when I have specified runat=server. I have thought
when you specified runat=server you can only use
event handler on the server ?

<%@ 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('Hello');
}

// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
&nbsp;
<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()" />

</div>
</form>
</body>
</html>


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4664 (20091206) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4664 (20091206) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top