Is it any difference between the two examples

T

Tony Johansson

Hello!

Below is two alternatives presented. Is the two alternatives equivalent ?
As you can see the only difference is that the html element and the head
element is moved below the script element

Aternative 1
**********
<%@Page Language="C#" %>
<html>
<head>
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
Label1.Text = "Clicked at " + DateTime.Now.ToString();
}
</script>
</head>
....
....
....
</html>


Alternative 2
**********
<%@Page Language="C#" %>
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
Label1.Text = "Clicked at " + DateTime.Now.ToString();
}
</script>
<html>
<head>
...
</head>
....
....
....
</html>

//Tony
 
A

Arne Vajhøj

Below is two alternatives presented. Is the two alternatives equivalent ?
As you can see the only difference is that the html element and the head
element is moved below the script element

Aternative 1
**********
<%@Page Language="C#" %>
<html>
<head>
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
Label1.Text = "Clicked at " + DateTime.Now.ToString();
}
</script>
</head>
...
...
...
</html>


Alternative 2
**********
<%@Page Language="C#" %>
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
Label1.Text = "Clicked at " + DateTime.Now.ToString();
}
</script>
<html>
<head>
...
</head>
...
...
...
</html>

You should go for alternative 3 - having the code in the
code behind.

If you have to choose between the two then go for alternative 1,
because alternative 2 does not have a single outer tag and it
is not valid XHTML and even HTML parsers could be confused.

Arne
 
T

Tony Johansson

Arne Vajhøj said:
You should go for alternative 3 - having the code in the
code behind.

If you have to choose between the two then go for alternative 1,
because alternative 2 does not have a single outer tag and it
is not valid XHTML and even HTML parsers could be confused.

Arne

Yes I know that using the code behind is the best way but this was just an
example.

//Tony
 
A

Arne Vajhøj

Yes I know that using the code behind is the best way but this was just an
example.

In that case you should chose based on XHTML/HTML validity. I assume
that you have tested that VS works fine with both, but any tool that
parse as XML would not be able to parse #2.

Arne
 

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