Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 jQuery append 方法以编程方式将 ASP.Net 按钮添加到 HTML。这是代码:
$("#form1 #container").append('<div id="cool"><asp:Button ID="Button1" runat="server" Text="Button" >/div> ');
但不知何故,它显示了这个错误
'Button' 类型的控件 'Button1' 必须放置在带有 runat=server 的表单标记内。
请帮我。谢谢。
无法asp:button通过 javascript 添加到页面,因为它是服务器端控件。
asp:button
您可以将纯 HTML 添加<button />到页面,但它不会像原来那样连接到回发和视图状态asp:button- 如果需要,您需要一些手动执行此操作的方法。
<button />
这是不可能的,jquery 只能附加 html 控件而不是服务器控件。看看这个。
差异。b/w 服务器和 html 控件