Solved

ASP.NET two forms on one page

Posted on 2007-04-07
4
792 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

18 Experts available now in Live!

Get 1:1 Help Now