What if I remove

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  

"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.
⭐ 5 followers.

💬 6 Replies
👁️‍🗨️ 1410 Views

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 Pagetitle>
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 Behindspan>
 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  out of

, 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 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 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