0

I have a page that displays employee information for a company. The list is split into 3 groups. Each group has an add button and an edit button. The buttons call the respective subform in a modal window.

Since the forms are built in vb.net and use ASP objects, they need the form to be wrapped in a form that has runat="server". I am unable to add the run at server directive to each of the 6 sub forms's form tags as I can only have one runat="server" per page.

To get around that, I added the directive to a form element that wraps the body of the page. Now I'm getting an error because of nested form elements. How do I get around this?

<body>
<form runat="server">

    <form id="popup1">
    </form>

    <form id="popup2">
    </form>

    <form id="popup3">
    </form>


    <form id="popup4">
    </form>


    <form id="popup5">
    </form>


    <form id="popup6">
    </form>

</form>
</body>

I read about the form elements getting a form attribute that ties the elements to a particular form as in form="form1" and so on. But I'm not sure if that will work in my case since some folks may try to use Internet Explorer which does not support the form attribute.

I'm thinking that I need to create only one modal form for my page, add all the elements for all six forms and then use logic to show/hide elements based upon which button is pressed. The problem is that the forms are rendered on the server side using asp elements and the button press is client side. I could use some javascript to handle this, but things could get messy. Additionally, the forms may get loaded with data or not depending on whether the button presses is add employee or edit employee.

Maybe I should create the 6 modal forms without using asp objects and stick to HTML objects. This negates the use of ASP's regular expression validators but I'm ok with that.

RCDAWebmaster
  • 319
  • 5
  • 17
  • You can unlimited runat attributes on a page. You can only have one form element. – IrishChieftain Nov 19 '18 at 16:24
  • 1
    That is not correct. I've been coding for years and can have multiple forms on a page as long as they are not nested. It's only when I want multiple forms on a page to have the runat="server" attribute that I run into problems. – RCDAWebmaster Nov 19 '18 at 16:43
  • Not with Web Forms without messy hacks: https://stackoverflow.com/questions/7544454/can-we-use-multiple-forms-in-a-web-page In the Web Forms world, a form tag with no runat does nothing. – IrishChieftain Nov 19 '18 at 17:02
  • Ah yeah. A form containing asp elements needs the runat="server" and you can only have one per page. If I create the form in plain HTML, I can have as many forms as I like on a page as long as they are not nested. In that case, I will have to build the 6 forms in HTML and use javascript to validate them. That's a bit tedious because I will have to change my form elements a bit but it will work. I wish there was a better way. – RCDAWebmaster Nov 19 '18 at 18:15
  • This is the Achilles Heel of Web Forms ;-) – IrishChieftain Nov 19 '18 at 18:56
  • I ended up developing the forms as straight HTML forms with no runat="server" and all is good. I then last night decided to combine the 6 forms into one since they were basically the same. now that there is only one, I could go back to a form with runat="server" but have invested too much effort to change it now. Honestly, I'm not the greatest when it comes to web forms and since I am more proficient with HTML anyways, I went that route and everything works just fine. – RCDAWebmaster Nov 20 '18 at 18:14
  • Glad you found a workaround. This issue always comes up when trying to add a PayPal badge to a Web Forms project. – IrishChieftain Nov 20 '18 at 18:42

0 Answers0