AllExperts > Experts 
Search      

Active Server Pages Programming (ASP)

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Chris
Expertise
I can answer pretty much any question relating to VB.NET and its use in a Windows environment. I can also handle most questions using C#. I specialize in ASP.NET web development and MSSQL database access, but have some stale knowledge of the old ASP - I'd prefer to avoid questions about it.

Experience
I have over 5 years of industry experience using VB.NET and other .NET technologies for web and database development.

Education/Credentials
I have some college education, but does it really matter in this field of work?

 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > ASP.NET

Topic: Active Server Pages Programming (ASP)



Expert: Chris
Date: 9/28/2007
Subject: ASP.NET

Question
Dear Sir,

I Create the following code in  macromedia Dream Weaver Mx 2004, while in Dream Weaver preview Page it's working Correctly,
But While opening the following page in IE Its Displays the following  Error Message. Please Find me the Better Soloution.

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<asp:TextBox text="Victory" runat="server"/>
</body>
</html>

Server Error in '/' Application.
--------------------------------------------------------------------------------

Control 'ctl00' of type 'TextBox' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'ctl00' of type 'TextBox' must be placed
inside a form tag with runat=server.

Source Error:

An unhandled exception was generated during the execution of the current web request.
Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[HttpException (0x80004005): Control 'ctl00' of type 'TextBox' must be placed inside a form tag with runat=server.]
  System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +1997503
  System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter writer) +48
  System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +17
  System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17
  System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
  System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +130
  System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +24
  System.Web.UI.Page.Render(HtmlTextWriter writer) +26
  System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
  System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1896




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

Answer
It's exactly as the error says - you can not place ASP.Net controls of any kind within HTML unless the HTML element you're placing them in (or one of its parents) has the runat="server" setting, as well as an id="someID" specified.  Similarly, the PostBack system will not work unless you've got these controls within a <form> tag.  In general, you should start with the template file that Visual Studio creates for you (which I've slightly modified to match your original):

<%@ Page  Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>

<!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">
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
   <asp:TextBox text="Victory" runat="server"/>
   </div>
   </form>
</body>
</html>


Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.