开发者

ASP.NET invalid element name StartTag error

For some reason, I'm getting this error when trying to test a code page on my computer.

It may have something to do with a faulty IIS installation, but I can't seem to find out what the problem is.

I get the following error:

error on line 1 at column 2: StartTag: invalid element name

Here is my Default.aspx:

<%@ Page Language="C#" %>

<html>

<head>

<title>Plating Trees</title>

<script runat=”server”>
 protected void Page_Load(Object Source, EventArgs E)
 {

/* Begin C# Code!*/

Tree tree1 = new Tree();

tree1.Grow(3);

tree1.Message();

 }

</script>

</head>

<body>

<p><asp:label runat=”server” id=”Output” /></p>

</body>

</html>

Tree.cs:

开发者_开发问答
/* A simple C# class! */

public class Tree
{

    public int height = 0;

    public void Grow(int h)
    {
        height += h;
    }

    public string Message()
    {
        Output.Text = "The height of tree1 is:<br/>” + tree1.height + feet";
    }

}


Not sure if this is the cause of your issue, but the double quotes around your attributes and code don't look valid.

<script runat=”server”>
<p><asp:label runat=”server” id=”Output” /></p>

should be:

<script runat="server">
<p><asp:label runat="server" id="Output" /></p>

and

Output.Text = "The height of tree1 is:<br/>” + tree1.height + feet";

should be:

Output.Text = "The height of tree1 is:<br/>" + tree1.height + "feet";


Your question is similar to this previous question in StackOverflow: “StartTag: invalid element name” in default.aspx, which seems like an IIS configuration issue.

From the link:

When I went into the ASP.NET tab for the virtual directory I noticed the ASP.NET version was not selected (it was an empty combo box). Choosing the .NET framework version did the trick.

Have a look at it, it might solve your problem :)


The main problem is that your Tree class does not have access to Output, because that property belongs to a different object, Default.aspx. You need to call Output.Text from Default.aspx instead of Tree. Also, I think geoff is right about the versus ". Therefore, edit your Page_Load as follows:

In your Default.aspx

<script runat="server">
protected void Page_Load(Object Source, EventArgs E)
{
  /* Begin C# Code!*/
  Tree tree1 = new Tree();
  tree1.Grow(3);
  Output.Text = tree1.Message();
}
</script>

In Message() you need to remove Output.Text. Next, you can't have the class Tree reference itself like tree1.height, so change it to either this.height or preferably just height. Also, remove feet because you don't have it defined anywhere yet. Note that you have a in this method too. Finally, take out the last " that was to the right of feet. Edit as follows:

In your Test class

public string Message()
{
  return "The height of tree1 is:<br/>" + height;
}

You can keep everything else the same, but personally, I would move the <script runat="server"> block to just below the <%@ Page Language="C#" %>

Also, I think you have bugs in your logic, but I'm sure you can figure that out once you get past this stuff.

(I ran it from my VS 2008 IDE)


@BOSS, perhaps you need to run aspnet_regiis tool to re-register ASP.NET in your IIS.

Go into your .NET framework command prompt and run "aspnet_regiis -i" to do this.

Reference: ASP.NET IIS Registration Tool (Aspnet_regiis.exe)

Also, note the following if you have multiple website in your IIS:

The -i flag causes the aspnet_regiis command to perform its work on every website on the box, not just the one that needs it. As the .NET framework 2.0 begins to ship there will be more developers and production servers running both version of the framework. Running the aspnet_regiis command with the -i flag will associate all websites on the box with the framework from where the command was run (there is one version of the aspnet_regiis command for every installed version of the .NET framework). It is also useful to note that the -i flag will reset auto-generated values with immediate impact on forms based logins and viewstate checksums. If you run the command with the -i flag on a live production server you may very well interupt the applications of logged in users of other applications on the same box. The “-i“ flavor of the command should never be run in a production environment unless there are no active users logged on, and all websites on the box happen to be on the same .NET framework version.

From: Running "aspnet_regiis -i" Not Always The Best Choice

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜