Reputation: 2701
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.
Upvotes: 0
Views: 1701
Reputation: 5818
That is not possible, jquery can only append html controls not server controls. Have a look at this.
Diff. b/w server and html controls
Upvotes: 1
Reputation: 337570
It is not possible to add an asp:button
to 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 an asp:button
would be - you would need some method of doing that manually if required.
Upvotes: 2