Psykopup
Psykopup

Reputation: 165

Dynamically create ASP.NET button control using jQuery

I know this can be done for regular HTML buttons, but can asp:Button be created dynamically using jQuery?

Here's my button with an onclick that calls a server-side function:

<asp:Button ID="btnYesGPS" runat="server" Text="Yes" CssClass="formButton" onclick="btnYesGPS_Click" />

Thank you for any guidance on this.

Upvotes: 1

Views: 2158

Answers (4)

nunespascal
nunespascal

Reputation: 17724

You say you are posting to a webservice. This can be done purely in javascript.

Add a ScriptService reference in your ScriptManager, and you should be able to call it from javascript. Then adding the button using jquery at client-side will suffice.

Adding a asp.net button at client side is not possible, and in this case not at all required.

If you need help refer here: asp.net web services

Upvotes: 0

Maksim Vi.
Maksim Vi.

Reputation: 9225

Since it looks like you have your server side logic already and just want to call it from client side, I see 2 options:

  1. Hide asp.net button by default (display:none) and show it if GPS API is available
  2. Call it via AJAX (WebMethod)

Personally I like the first option.

Upvotes: 1

cusimar9
cusimar9

Reputation: 5259

As Claudio mentioned you cannot create ASP.NET controls on the client side, however you can create elements on the client side which use jquery (or AJAX) to post back to the server side and perform some server side function.

If you give us some context to your question we may be able to provide a more detailed answer

Upvotes: 0

Claudio Redi
Claudio Redi

Reputation: 68400

No, you can't create ASP.NET controls with jQuery. They are server specific while jQuery is executed on client. They just belong so different and separated worlds.

Upvotes: 1

Related Questions