这里是我的示例代码:如何在使用javascript的<form>标签内追加<asp:Button />等。
<script type="text/javascript">
$(function() {
$('body')
.append('<form id="form1"></form>'); //append a new form element with id mySearch to <body>
$('#form1')
.attr("runat", "server")
.append('<asp:Button runat="server" ID="btn1"/>');
});
</script>
这是我的身体标记看起来像:
<body>
</body>
我得到这个错误:
Control 'btn1' of type 'Button' must be placed inside a form tag with runat=server.
提前感谢! :)
更新:我想省略
.append('<asp:Button runat="server" ID="btn1"/>');
当我运行萤火虫我得到这个:
<body>
<form id="form1" runat="server"></form>
</body>
它有中用runat = “服务器”。为什么我不能把我的asp:Button放在里面? O_O
只需使用一个常规的输入按钮......这正是'asp:button'呈现的样子。 – MikeSmithDev
是的,它的工作原理,但我想使用像asp:Repeater'asp ctrls绑定我的数据。有没有其他方法?无论如何,谢谢@MikeSmithDev –
你不能通过Javascript添加服务器控件。你为什么甚至想要这样做?为什么你不能直接在页面中输入这些控件并摆脱你的Javascript? – MikeSmithDev