Solved

ASP.NET two forms on one page

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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