Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form tag on ASP.net page

Tags:

asp.net

I have a web application that has a page that loads the content from the database. I want to be able to put a form in the dynamic content, but .net doesn't let the inside form perform it's action. Is there a way to allow this or some other way I can get a form on a dynamic content page?

--EDIT--

I think I need to clarify something. This is an aspx page that loads content from the database. As far as I know, the text I pull from the db and stick in the Label is never compiled or processed by the .net wp, thus I can't use the code behind to fix this issue.

like image 906
jhunter Avatar asked May 29 '09 15:05

jhunter


2 Answers

This is a common problem, when you want to have a non-postback form to a 3rd party site (like a PayPal button, for example).

The problem occurs because HTML doesn't let you have form within a form, and most ASP.NET pages have a <form runat="server" /> "high up" in the HTML (or in the Master page).

My favorite solution is to hide the "high up" form tag, while still showing all of the content. Then you can feel free to dump any tags you want in the body. If you do this dynamically you can choose on a page-by-page basis which pages have custom forms.

I created a class called GhostForm.cs to handle this. You can read all about it here:

http://jerschneid.blogspot.com/2007/03/hide-form-tag-but-leave-content.html

like image 139
JerSchneid Avatar answered Sep 21 '22 05:09

JerSchneid


There can only be one form on the page (the asp form); you have to use that form somehow.

To clarify, there can only be one form processed.

like image 34
Joe Phillips Avatar answered Sep 22 '22 05:09

Joe Phillips