What if I remove <form id="form1" runat="server"></form>

If I am creating an aspx page, which does not need to be a form, i.e. no input is taken from the user, do I need to encapsulate the whole page with in  

<form1 runat="server">

 

What are the implications of removing the form? I realize there will be no viewstate, and again, I won't be able to accept user input, but will everything else work as expected?

It seems to be so far, I've just not seen ANY examples where the form tag has been removed.

Thanks,

Darragh

0
darragh
8/9/2006 4:20:25 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

6 Replies
1982 Views

Similar Articles

[PageSpeed] 50
Get it on Google Play
Get it on Apple App Store

You need the server-side form tag if you are going to have server-side controls on the form.

Ryan

Ryan Olshan
ASPInsider | Microsoft MVP, ASP.NET
http://ryanolshan.com

How to ask a question
0
StrongTypes
8/9/2006 4:38:30 PM

That's what I originally thought, but it's not the case. Give it a try!

-Darragh

 

0
darragh
8/9/2006 5:01:17 PM
darragh:
That's what I originally thought, but it's not the case. Give it a try!


Could you elaborate? Posting the code of your form would also help.

Ryan

Ryan Olshan
ASPInsider | Microsoft MVP, ASP.NET
http://ryanolshan.com

How to ask a question
0
StrongTypes
8/9/2006 5:05:15 PM
My ASPX page looks like this:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>
</head>
<body>    
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
</body>
</html>
My Code-Behind for the above page looks like this:
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label1.Text = "Code Behind"
    End Sub
End Class
And the page renders like this:
<!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>
Untitled Page
</title></head>
<body>
 
 <div>
	<span id="Label1">Code Behind</span>
 </div>

</body>
</html>

 

Not the lack of any form elements in the ASPX page and the HTML page. My real question is, is this supposed to work?

-Darragh

0
darragh
8/10/2006 8:46:37 AM

   when I write a  <asp:Button runat="server"/> out of <form runat="server"> , the page throw exception @ System.Web.UI.Page.VerifyRenderingInServerForm(Control control)

    thus,I searched Page.VerifyRenderingInServerForm Method  @ msdn and got :

Controls that are required to be inside <form runat=server> tags can call this method before they render so that an error message is shown if they are placed outside the tags. Controls that post back or depend on registered script blocks should call this method in an override of the Control.Render method. Pages that have a different way of rendering the server form element can override this method to throw an exception under different conditions.

Server controls that post back or use client-side script will not work if they are not enclosed in the HtmlForm server control (<form runat="server">) tags. These controls can call this method when they render to provide a clear error message when they are not enclosed in the HtmlForm control.

0
Dragon
8/10/2006 9:46:44 AM

Thanks, that MSDN reference seems to suggest that there's no problem with removing the <form> tag when I will only be using controls such as panels, images, labels, and repeaters (i.e. controls which don't accept user input and don't post back).

I'll not have to worry about viewstate either. Nice 1.

-Darragh

 

0
darragh
8/10/2006 11:16:07 AM
Reply:

Similar Artilces:

can I delete <form id="form1" runat="server"> and </form>
Hi: Our website is written by using simple html code, one of the page has some virtual shopping cart code with <form> ....</form>, (for example here: http://www.centercoin.com/coin_supplies/coin_collecting_starter_set.htm ), if I have 10 products, I will have 10 of <from> ...</form> in this page, that is ok. Now, I am trying to redesign the website using asp.net2.0, I notice all the asp page will automatically create a <form id="form1" runat="server"> ...</form>, such as: <html xmlns="http://www.w3.org/19...

<form id="form" runat="server">
hey i have a very similar problem to this thread http://forums.asp.net/thread/1440587.aspx"Control 'ctl00_ContentPlaceHolder1_Login1' of type 'Login' 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_ContentPlaceHolder1_Login1' of type 'Login' must be placed inside a form tag with r...

MasterPage does not work with <form id="Form1" runat="Server">
When I add my masterpage to my content page I am getting - A page can have only one server-side Form tag. Content page: (VB.Net)1 <%@ Page language="VB" Inherits="dotForumPostReply.addReply" EnableEventValidation="False" 2 CodePage="1252" MasterPageFile="masterpage.master" %> 3 <%@ MasterType VirtualPath="masterpage.master" %> 4 <%@ Register NameSpace="OSS" TagPrefix="OSS" %> 5 <%@ import namespace="System" %> 6 <%@ import namespace="System.Data&...

Error on <form enctype="multipart/form-data" runat="server">
Hi to all... i have this problem which occured when i was uploading a picture into the SQL 2000. i am using VB script and Microsoft Visual Studio 2005... the error on"<pages enableEventValidation="true"/>"... can anyone help me??  i am using a master template for my webpage... everything work jus fine before i insert this "<form enctype="multipart/form-data" runat="server">" at the top of the page after "<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server&...

<form id="form3" runat="server">
i am really confused about the <form id="form3" runat="server">  error i receive the thing is LoginStatus1 andCreateUserWizard1both require their components to run at the server. however only one form server is allowed in the document. i receive this error message in the browser, and vice versa for the other component.Server Error in '/vwd test/Techworld' Application. A page can have only one server-side Form tag. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for mor...

Why is <form id="form1" runat="server"> added to every new aspx page?
 Hi all, Can someone tell me why <form id="form1" runat="server"> is added to every new aspx page? And what I should do if I need to have one or more search forms on the page as I beleive I can't nest forms? ThanksDenis Hi, please read this article: Form-based Programming in ASP.NET. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons. You may also read the following:http://www.vbdotnetheaven.com/UploadFile/avi_sanjay/MultiForms.htm12142006233855PM/MultiForms.htm.aspx http://www...

Programmatic equivalent of <form runat="server"> </from>
When designing an ASPX page, WebControls must be contained into a tag <form runat="server"></form>.I am trying to achieve the same effect but in a programmatic manner within a .Net library (using HttpHandlers).Does anyone has an idea how to do that?Thanks in advance,Joann├ĘsLokad.com, time-series forecasting  Actually, I might have succeeded to solve this issue, but I am not too sure if it's the "right" way to do it.public class MyPage : Page { protected override void CreateChildControls() { HtmlForm htmlForm = new HtmlForm(); Controls.Add(htmlF...

<authentication mode="Forms">forms name=".AUTHCOOKIE"
Hi there, I used authentication mode="Forms" with AUTHCOOKIE. my web.config looks like this <system.web> <authentication mode="Forms"><forms name=".AUTHCOOKIE" loginUrl="default.aspx" protection="All" /> </authentication><machineKey  validationKey="AutoGenerate" decryptionKey="AutoGenerate" validation="SHA1" /><authorization> <deny users="?" /> </authorization>   </system.web>    So far so good, but ... I have a f...

<sessionState timeout="x"/> vs <forms timeout="y"/>
How to configure web app: x=y x>y x<y ?...

<ypbp:CategoryTree id="categoryTree" runat="server"></ypbp:CategoryTree>
Hi All, I hope you can help a very confused beginner. I am writing a site that has a navigation tree configured from a database. I wanted to create a reusable piece of code that "draws" the navigation tree based on a request parameter that indicates to the code how to draw the tree. For example, the first time the page loads it will draw all the top level menu items only, and when a user clicks on one of those options it would draw all the top items and also the children of the item just clicked on etc... I want this to be reusable because I am writing an admin backend to the website as we...

I've placed <forms loginUrl="home.aspx"></forms> in web.config and now all users that log in go to default.aspx
I've placed <forms loginUrl="home.aspx"></forms> in web.config and now all users that log in go to default.aspx.        <authentication mode="Forms">        <forms loginUrl="home.aspx"></forms>      </authentication>What attribute I should add, to make the user stay on the same page. Btw when I remove  <forms loginUrl="home.aspx"></forms>, users stay on the same page after login.Thanks. try one of these.....

Why does <form runat="server"> render <div> around viewstate hidden variable?
I can't figure out why asp.net thinks it needs to render a div around the viewstate hidden variable, or if there's any way to get it to stop doing it:<form name="aspnetForm" method="post" action="default.aspx" id="aspnetForm" class="mainform"><div><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMDUyNjYzMjhkZA1/6gmEk+w4wUiViNwm8AqBxBo1" /></div> It screws up attempts to style pages in certain ways, and since there's no way to put an id or cl...

Regular Expression to remove "/", "\", "<", ">" and "="
Can anyone please show me the regular expression to reject a string ("<blue", "right>" etc.) which has the following expression in it: "/", "\", "<", ">" and "="  hi, It may Help u.. it is in Class file u may use this expressin in validation controls also. Regex objReg = new Regex(@"^[^,.?/\~|`;:'<>]*$", RegexOptions.Singleline); Regex objReg = new Regex(@"^[^,][^.][^?][^/][^\][^~|][^`][^;][^:][^'][[^<][^>]$", RegexOptions.IgnoreCase);Thanks &...

"<table></table>" and "<frameset><frame></frame></frameset>" in perl/tk
Dear my friends... Anybody would be so kind telling me what is similar in perl/tk to arrange the location of a form written in perl/tk? I want a nice look for my perl/tk application. Somewhat like this below: 1. Name : <place to type-in> 2. Address : <place to type-in> 3. Telephone : <place to type-in> I have made the main menu of my application with "Menubutton". And I want if the user click on the menu that what the user see is only the aimed application displayed on the determined area (under the main menu) but the menu has no change in po...

Web resources about - What if I remove <form id="form1" runat="server"></form> - asp.net.web-forms

Resources last updated: 1/20/2016 1:51:22 AM