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 |
![]() |
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 |
![]() |
That's what I originally thought, but it's not the case. Give it a try!
-Darragh
![]() |
0 |
![]() |
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 |
![]() |
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 ClassAnd 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 |
![]() |
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 |
![]() |
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 |
![]() |