[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

ASP.NET two forms on one page

Posted on 2007-04-07
4
Medium Priority
?
830 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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