Click here to Skip to main content
6,631,889 members and growing! (16,278 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Beginner

Multile form tags with Runat=Server Attribute

By Satheesh G

This artcile shows how to use multiple form tags with runat=server attribute
Windows, .NET, ASP.NET, Visual Studio, Dev
Posted:29 Apr 2006
Views:23,736
Bookmarked:12 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
19 votes for this article.
Popularity: 1.94 Rating: 1.51 out of 5
13 votes, 68.4%
1
2 votes, 10.5%
2

3

4
4 votes, 21.1%
5

Introduction

When you ask an Asp.NET beginner (ofcourse guys with some .NET experience too), how many form tags can be kept on a single page, you get the answers like One, Any number of form tags but only one with runat=�server� attribute etc. However the fact is .NET allows you to put any number of form tags with runat=�server� attribute without getting runtime error By default page will never show any error though it has got more than one server side form tag at compile time, as the error will be thrown only when ASP.NET calls renderControl method on all controls of the page.

 

However, while doing so, the trick lies in making only one form tag visible at any given time.

 

The article tries to prove the fact on how to handle it.

 

 

To show this, I have taken a single web form which by default creates a form tab with ID as form1, I have just modified it to FirstFormTag.

 

Drag a Panel from the toolbox on to the form. Go to the HTML section and insert another form tag with runat=server attribute and the whole html looks like this

 

<form id="FirstFormTag" method="post" runat="server">

                                    &nbsp;

                                    <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 48px" runat="server"

                                                Height="32px" Width="120px">Label On First Form</asp:Label>

                        </form>

                        <asp:Panel id="pnlForSecondForm" style="Z-INDEX: 101; LEFT: 184px; POSITION: absolute; TOP: 40px" runat="server"

                                    Width="104px" Height="96px">Panel

                                    <FORM id="SecondFormTag" method="post" runat="server">

                                                <asp:Label id="Label2" runat="server">Label On Second Form</asp:Label>

                                    </FORM>

                        </asp:Panel>

 

 

At this time Intelliscence will not show any error sign. If you run the project now, it throws up the error saying that A page can have only one server-side Form tag

At this stage, go to the code behind class of the webform and in Page load event, Make the visibility of Panel to false.

 

Now run the application, and the page will be displayed without any error though two form tags are available with runat=server attribute.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Satheesh G


Member

Occupation: Web Developer
Location: India India

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralMy vote of 2 PinmemberMaxdd 715:10 18 Nov '09  
GeneralMy vote of 1 PinmemberHristo Bojilov4:48 1 Sep '09  
GeneralHow about displaying two forms at same time PinmemberRajkumar Aili1:00 20 Apr '07  
QuestionPanel visble false Pinmemberdadvav7:13 30 Apr '06  
AnswerRe: Panel visble false PinmemberSatheesh G18:43 1 May '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 29 Apr 2006
Editor:
Copyright 2006 by Satheesh G
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project