I am trying to add an ASP.Net Button programatically using jQuery append method to HTML.
Here is the code:
$("#form1 #container").append('<div id="cool"><asp:Button ID="Button1" runat="server" Text="Button" >/div> ');
But somehow it shows this error
Control ‘Button1’ of type ‘Button’ must be placed inside a form tag with runat=server.
Please help me. Thanks.
It is not possible to add an
asp:buttonto a page via javascript as it is a server-side control.You can add a plain HTML
<button />to the page, but it will not be hooked up to postback and viewstate as anasp:buttonwould be – you would need some method of doing that manually if required.