views:

827

answers:

4

I need to supply an html form (not a server form) for searching within an asp.net web-forms website. The form will post to another website where an indexed search is performed. Seeing as nested forms don't work well in asp.net, what is the simplest approach for this?

The nested form is a simple html form that performs a "get" against the search website, which I do not have programmatic control over.

Update: I resolved my issue by simply moving the server form to the appropriate place on the page, rather than having it surround the entire page. However, I'm still wondering how this would be handled if the html form needed to be placed physically between server controls (which require the server form).

A: 

maybe you try Server.Transfer() to your target page that do the search from a button for example!

martani_net
+1  A: 

Not only do nested forms "not work well," you basically can't have >1 form per page at all. The simplest approach is the approach you are forced to go with: write a page that only uses one <form runat="server"></form>. Since you need search functionality, is there no ASP.NET search box control that you could use?

Have a read here.

Matt Ball
Righto - "can't have >1 form per page at all" meaning forms with runat="server". You *can* have other forms on the same page as long as they don't have runat="server". Sorry if that was less-than-clear.
Matt Ball
+1  A: 

Nested forms don't work well in HTML full stop! You should never do it.

Perhaps you mean more than one form on page? Whilst it's true you can only have one form with runat="server", I can't see any reason why you couldn't have a standard form (not server form) that posted to another site at the same level (ie. not nested).

Dan Diplo
+1  A: 

However, I'm still wondering how this would be handled if the html form needed to be placed physically between server controls (which require the server form).

You can place controls on your page without requiring an HtmlForm.

In your case there's no issue declaring another form markup, but you could also just use some search control on your main form and make it issue a GET to that website.

Right, I didn't actually mean an "HtmlForm" server control. I had used a form tag with the get method and upon clicking it's contained button, the entire page posted back rather than going to the "action" page of that form. It sounds like you are saying that should work? Perhaps I overlooked something else if so.
Jeremy