[英]ASP.NET Website: page with multiple forms
I'm having a problem while creating dynamically a web page in ASP.NET (C#). 在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. 我需要在该页面中插入多个表单标签,我知道我不能使用runat =“ server”属性放置多个表单标签,并且不需要它。
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") ) 我想将它们从C#中放置(我必须管理的每个元素一个),而没有runat属性,但是我用于插入表单的HtmlForm对象会自动添加runat属性,而我无法删除它(尝试过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. 我多次将其添加到我的div中,它可以正常工作。 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.
关键是我不想插入所有我的HTML对象(将它们写入字符串)并使用InnerHTML方法添加它。 I'm looking for an object that manage a Form without the runat attribute or a way to remove that from HtmlForm .
我正在寻找一个管理表单的对象,而该对象没有runat属性,也没有从HtmlForm删除该属性的方法。
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. 用户控件可能是最干净的解决方案,但是您可以添加
HtmlGenericControl
而不是未绑定到任何特定属性的HtmlForm
对象。
Dim ctrl As New HtmlGenericControl("form")
ctrl.Attributes.Add("id", "someID")
ctrl.Attributes.Add("method", "POST")
ctrl.Attributes.Add("action", "")
OuterDivContainer.Controls.Add(ctrl)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.