Saturday, March 31, 2012

Server side forms, using more than 1 per page

Hi,

This has to be a real easy one, I must be missing some dead simple concept somewhere...or be completly stupid (which is more likely if I'm honest:)...so appologies for my stupidity here...

I'm just playing around trying to get to grips with things but I have a master page that uses a TreeView for the navigation in the LHS of the page. This requires wrapping in a <form runat=server> tag to work.

The content page that uses the master page has a gridView (or rather I wish it would do!) and this also requires wrapping in <form runat=server> tag to work. You know where this is going don't you...when I run the page, I'm politely told as my masterpeice crashes and burns "A page can have only one server-side Form tag.".

I refuse to believe that you cannot have this combination of controls in a page, I'm not exactly pushing the limits of the .Net framework here...So I'm guessing it's the way I'm doing things...what do I need to do to get this to work given that both contorls need wrapping in the FORM tag and that these are essentially 2 seperate pages (from a design point of view at least)?

many thanks for any help

Mark

You can have any number of forms, but only 1 server side form indeed. Thats because of the way the page model works, the server side form is used for postback purposes, where all controls are required to be accessible. There's nothing preventing you from having 2 submit buttons doing 2 different things however, so there really is no need for 2 forms. You can even use the CrossPagePostBack feature of .NET to post to two different other pages as required...

Thanks for the reply...

So basically I should use the FORM tag in the masterpage to "wrap" everything, including the content page placeholder, which seems to work.

I don't need the submit buttons that you mention in this situation it's just that the controls require the form tag to work (but I know where you're coming from with that). I can see that this approach with master pages might cause problems as things progress but I'll worry about that as I go..

Thanks again,


Masterpages work fine that way too, since the form tag is in the master page, and wraps all the containers. Honestly, I tend to even forget about that form tag...its just there for show more than anything.

0 comments:

Post a Comment