Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML forms unavailable in .NET?

Status
Not open for further replies.

BadRabbit

Programmer
Nov 14, 2002
28
GB
I'm new to ASP.NET and I am so hating it. :| Is it true that you can't use HTML forms any more in an ASP.NET page? All I want is a simple search box that resubmits to the page by way of a button (which calls some javascript).

First off, I tried to include an HTML form but nested forms aren't allowed (i.e. with the global "runat=server" thing). So I give the runat server form a name and some controls, etc. but when the code is generated it's always changed to "_C10" or some such stuff. So then I just made the button non-submit and called some js onClick, which worked great. Except when you press RETURN it goes to the global form, so it's useless.

So what I'm asking is, is there any way to implement this simple thing in ASP.NET without using ASP.NET controls (when I try, using WebMatrix, the editing interface consistently screws up the page format and rewrites my code incorrectly so it fails). It must be an HTML form (or similar). And I have many screens to convert that use multiple forms in a page - this seems impossible now.

Any help would be appreciated as I have come to a total stop.
 
Well, I've got around it just by including "onsubmit="return false" in the main form, thus disabling RETURN. It seems strange that a new language invalidates the very environment and useful features it's trying to integrate with.
 
Hopefully I can help clarify some things for you. ASP.NET is first off a completely new way of doing things and often requires a completely new way of thinking.

The following analogy assumes that all pages are .aspx pages
Your basic route for a page is that the server gets a request for a page. The server adds the dynamic information according to the programming logic in that page and sends a html & javascript page to the client. The client interacts with that page. Once finished triggers an onclick event which is sent along with any changed data back to the server. The server then processes the click event and performs some action. This may be a redirect to another page based on what happened in the first page. In this case the circle starts over again.

Looking at what you were doing you could put the search button and fields on the form that you were trying to do a submit to. When the search button is clicked the server gets the event and fills in say a datagrid with the results of the search.

You no longer need 2 pages to accomplish one simple task. Everything needed can be included on that one page.

If you are still or I have confused you even more, feel free to ask. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Hi Mark,

Thanks for the reply. The immediate problem I got when I tried this was that when I included the name attribute in the main form tag (e.g. name="myForm") the served HTML had changed the name="_ct10" or something, so none of my check scripts worked. Of course, I could have changed my scripts but if this name is being auto-generated how do I know it won't change?

Also, some of my screens have several forms. For example, a contact form, and at the top a keyword search box and a category search box, which all have different actions when return is pressed. I've seen articles about displayed several forms on a page but to be honest they're beyond me (certainly at this stage)! I suppose I could have logic that branches depending on what fields are filled in, but this might cause incorrect operation - say if the user fills in a search but then decides to use the contact section - what happens when he presses RETURN?

I'm sure there's something that I missed - but I'm probably just a dinosaur who wants to code everything by hand!
 
Often you can use the validation controls along with your other controls to validate the form. This controls are server side and dynamically create the javascript so that no matter what the name of the control turns out to be it will always work.

If you have several forms on a single page the best thing to do might be to put each form into a user control and add that to your page. As far as the Enter/Return keypress there is a new 3rd party addin that takes care of this perfectly see the Jan 27 2003 post by Link9 in this thread855-288280. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top