Solved

ASP.NET two forms on one page

Posted on 2007-04-07
4
781 Views
Last Modified: 2008-02-01
I understand that ASP.NET only allows one form tag with runat="server" per page.

Suppose I have a search form on top of the page that is on every page.

How would I add another form, such as a contact us form? This would mean both forms are required to be on the same page, but of course I get an error in doing so. How do I get around this?
0
Comment
Question by:EVelasco
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:steveberzins
ID: 18870328
it may work if, you're other form is just a plain old form(no runat="server"), and none of the controls inside it can be server side controls then as well, so if you can handle that...also, the action must be a different page, since it will be more or less, a plain old vanilla html form...

    <form id="form2" action="contact.aspx">
        <input id="name" name="name" />
        <input id="phone" name="phone" />
        <input type="submit" value="Submit" />
    </form>
 
if this is not what you're after, maybe a little more of the why, may help someone help you with an elegant solution.
And what version of .NET?
in 2.0 you may be able to take advantage of cross page posting to do what you want with one form, and using a special button attribute that will cause it to submit to a different page...but again, a litle more info would help someone help you
0
 

Author Comment

by:EVelasco
ID: 18870355
The reason I want to use runat="server" is so that I can specify the link as ~/search.aspx and ~/admin/page.aspx

Then, the search form works from different directories because ASP.NET will handle the link correctly.

Also, the search form is on the master page. Other pages that inherit this page cannot have its own form. That's not good.


0
 
LVL 14

Accepted Solution

by:
steveberzins earned 250 total points
ID: 18870459
as far as I know, you just can't do two server side forms.

I think you could use ResolveUrl()...to build the correct link on the non-server side form, if that is all you're after...but with master pages this seems problematic at best...

but, if you are you using .NET 2.0, then you could use the search button in the same form, that will post to a search page instead of the default one, and since you're using this in the master page, it seems like a good way to go. <asp:Button Text="Search" PostBackUrl="~/search.aspx" .../>

and I think I answered my question, master pages = .net 2.0 :)
0
 

Author Comment

by:EVelasco
ID: 18873030
I did use ResolveUrl() and it worked as expected. Thanks. I still hope that in the future, we can have multiple and separate forms.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now