![]() |
Web Development »
ASP.NET »
General
Beginner
Multile form tags with Runat=Server AttributeBy Satheesh GThis artcile shows how to use multiple form tags with runat=server attribute |
Windows, .NET, ASP.NET, Visual Studio, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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">
<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.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
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 |