简体   繁体   中英

ASP.NET Website: page with multiple forms

I'm having a problem while creating dynamically a web page in ASP.NET (C#).

I need to insert multiple form tags in that page, I know that I can't put more than one with runat="server" attribute and I don't need it.

I want to place them from C# (one for each element I've got to manage), without the runat attribute but the HtmlForm object that I use for insert the form adds the runat attribute automatically and I can't remove it (tried with form.Attributes.Remove("runat") )

If I use a simple string like:

"<form id="someID" method="POST" action=""></form>"

and I add it multiple times into my div it works. The point is that I don't want to insert ALL my HTML objects writing them in a string and add it with InnerHTML method. I'm looking for an object that manage a Form without the runat attribute or a way to remove that from HtmlForm .

If you want to add controls dynamically to a page and make the web page render them as pure html, instead of rendering asp:Controls you can use the Literal control. Check this link or this one

A user control is probably the cleanest solution but you can add an HtmlGenericControl instead of a HtmlForm object which isn't bound to any specific attributes.

Dim ctrl As New HtmlGenericControl("form")
ctrl.Attributes.Add("id", "someID")
ctrl.Attributes.Add("method", "POST")
ctrl.Attributes.Add("action", "")
OuterDivContainer.Controls.Add(ctrl)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM