multiple forms/one form on a templated page

Jore

Newcomer
Joined
Jan 24, 2005
Messages
18
Location
Almost polar
Hi!

I use one sort of templating technique in asp.net. I have a single header and footer added before and after every content page in my development site.

Here is the the basepage class that builds the final page with header.ascx, content.aspx and footer.ascx:
Code:
' BasePage.vb
Public Class BasePage : Inherits System.Web.UI.Page
  Private _pageTitle As String

  Public Property PageTitle() As String
    Get
      Return _pageTitle
    End Get
    Set(ByVal Value As String)
      _pageTitle = Value
    End Set
  End Property

  Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
    Me.Controls.AddAt(0, LoadControl("Header.ascx"))
    MyBase.OnInit(e)
    Me.Controls.Add(LoadControl("Footer.ascx"))
  End Sub
End Class

Public Class BaseControl : Inherits System.Web.UI.UserControl
  Public Shadows ReadOnly Property Page() As BasePage
    Get
      Return CType(MyBase.Page, BasePage)
    End Get
  End Property
End Class

In the header.ascx file I have a calendar control and two dropdownlists that submit values to different pages. And in the content (the actual aspx page) I have a datagrid control that needs to reside inside form tags with runat="server" set.
Here's the problem: I have a <form runat="server"> </form> tags in the header.ascx containing the controls. And I can't add another pair of form tags with the runat="server" option to the content pages. Nor can I begin the form in header and end in footer. Asp.net always gives out an error.
So How could I accomplish having working form elements in both header.ascx and content?

Btw. I am using webmatrix and therefore don't have the same ease in codeing the pages that visual studio users have. So If you have any suggestions please give them in a way that I can use without vs.

--Jore
 
Last edited:
If you come across a situation where a aspx or ascx needs more than 1 <FORM> tag, then all forms after the 1st need to be hosted in an ascx. Keep the control/form ration 1:1. so for each <FORM> after the 1st <FORM>, you'll need a control to host the form. You can't stuff multiple <FORM> tags in an ascx. I'm assuming all <FORM> tags have the 'runat' attribute set to 'server'.

Personally, I think your header/footer system thing is the wrong approach to take when creating a templated website. I know from 1st hand experience.
 
Well I wouldn't need more than one <form>. But there are web controls (like textboxes) in both header and content pages. And if the beginning <form> tag and the ending </form> tag are placed in different files then asp.net produces error again. i.e. header.ascx would contain the beginning <form> tag and the content page (order.aspx) would contain the ending </form> tag.

Ok. If there isn't a way to make 2 separate (html)forms with runat="server" in ascx and aspx pages or place the beginnin and ending in different files, I quess I have to think of something else.

Btw what kind of approach would you suggest for templating the website?

--Jore
 
If the controls are placed on an aspx page then they can appear between the aspx page's <form> </form> tags - that way they do not require their own form elements.

A better approach can be found here
 
PlausiblyDamp said:
If the controls are placed on an aspx page then they can appear between the aspx page's <form> </form> tags - that way they do not require their own form elements.

A better approach can be found here

I'm sorry but that's another weak attempt...where do i begin... loss of wysiwyg... the outputing of html being done in the base class, The AddToBase method doesn't return the control that was added, so forget about being able to add attributes to the control created by the method..

Good intentions, bad execution/implementation. Until asp.net 2.0 comes out, I'm gonna have a field day with these types of implementations.
 
Back
Top