?
Solved

ASP.NET two forms on one page

Posted on 2007-04-07
4
Medium Priority
?
827 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 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