Jump to content

Is this code supposed to appear in the HTML page info?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
eindoofus

eindoofus

    Newbie

  • Members
  • Pip
  • 3 posts
I'm reading "Beginning ASP .NET 4 in C# and VB" and the book asks me to look at the HTML source after loading the page that I created with the following code:

ControlsDemo.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ControlsDemo.aspx.cs" Inherits="Demos_ControlsDemo" %>


<!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></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    

      <asp:TextBox ID="YourName" runat="server"></asp:TextBox>

      Your name<asp:Button ID="SubmitButton" runat="server" 

        onclick="SubmitButton_Click" Text="Submit Information" />

      <br />

      <asp:Label ID="Label1" runat="server"></asp:Label>

    

    </div>

    </form>

</body>

</html>


ControlsDemo.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;


public partial class Demos_ControlsDemo : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {


    }

    protected void SubmitButton_Click(object sender, EventArgs e)

    {

      Label1.Text = "Your name is " + YourName.Text;

    }

}

And it generates the following HTML:


<!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><title>

</title></head>


<body>


    <form method="post" action="ControlsDemo.aspx" id="form1">


<div class="aspNetHidden">


<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA3NjE4MDczNmRkRGmHS7RUhqAsayIODjq5pVJOcGbUHV0WvUwTwAHUntw=" />


</div>


<div class="aspNetHidden">


	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwL1/Mu5BALTydp0ArK44tQL6C3smRvQPjZBKPU4WeN35xjWrwcelGNXJR2senwT5+I=" />


</div>


    <div>

 

      <input name="YourName" type="text" id="YourName" />


      Your name<input type="submit" name="SubmitButton" value="Submit Information" id="SubmitButton" />


      <br />


      <span id="Label1"></span>

   

    </div>


    </form>


</body>


</html>


In the book there is no mention of the div tags containing the class aspNetHidden. Is that code supposed to be displaying in the HTML code? I find it kind of strange.

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
It appears since ASP.NET 2.0 to be XHTML compliant they add those tags around input fields, they later on added the aspNetHidden id so you can differentiate it through CSS styles, it is purely an automatic process.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users