0

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.

0

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I am working on using a table from sql to create a gallery and add dynamic asp:buttons to it so that when the user clicks the button, it redirects with a session. But as you said it's not possible with jquery so please suggest another way. Thanks
You're probably best off starting another question about that.
Try sending a ajax response to the page you are trying to get the asp button on, and then add the element using jquery or js.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.