1

note that i'm using asp.net with vb.net

jquery:

$("#create")
.button().click(function () {
$("#dialog-form").dialog("open");
});

$("#LinkButton3").click(function () {
        $("#dialog-form").dialog("open");
        return false;
    });

asp:

<asp:TemplateField HeaderText="Edit">
    <ItemTemplate> 
        <asp:LinkButton ID="LinkButton3" runat="server">LinkButton</asp:LinkButton>
    <a href="#" class="table-actions-button ic-table-edit" id="create"></a>
     </ItemTemplate> 
</asp:TemplateField> 

the dialog opens for the a tag but does not open for the linkbutton can anyone tell me why my code is not working?

User7291
  • 1,095
  • 3
  • 29
  • 71
  • You need the client id of your link button: http://stackoverflow.com/questions/5392958/getting-id-from-asp-net-runat-server-in-jquery – Pete Sep 26 '13 at 10:09

5 Answers5

1

The id of linkbutton on client side would be different so use the ClientID to bind the event. Also put binding code indocument.ready. Assign a class to linkbutton and use class selector to bind event.

Html

<asp:TemplateField HeaderText="Edit">
    <ItemTemplate> 
        <asp:LinkButton ID="LinkButton3" runat="server" class="someclass">LinkButton</asp:LinkButton>    <a href="#" class="table-actions-button ic-table-edit" id="create"></a>
     </ItemTemplate> 
</asp:TemplateField> 

Javascript

$('.someclass').click(function () {
    $("#dialog-form").dialog("open");
    return false;
});

If you need to use id for select then use attribute selector with starts with wild card.

$('[id=^LinkButton3]').click(function () {
    $("#dialog-form").dialog("open");
    return false;
});
Adil
  • 146,340
  • 25
  • 209
  • 204
0

Use ClientID to get server control in jquery like this.

  var create= "#<%=create.ClientID%>";
    $(create).on('click', function() { 
      $("#dialog-form").dialog("open");
    });

Don't forget to include js file and js code inside document.ready .

4b0
  • 21,981
  • 30
  • 95
  • 142
0

Try this

Add UseSubmitBehavior="false" to your asp link button

your html

<asp:TemplateField HeaderText="Edit">
    <ItemTemplate> 
        <asp:LinkButton ID="LinkButton3" runat="server" UseSubmitBehavior="false">LinkButton</asp:LinkButton>
    <a href="#" class="table-actions-button ic-table-edit" id="create"></a>
     </ItemTemplate> 
</asp:TemplateField> 
SarathSprakash
  • 4,614
  • 2
  • 19
  • 35
0

LinkButton is server side asp.net controls which causes postback. Another point is you are not using the correct id of the control it's changed. Try with $('#<%=LinkButton3.ClientID%>').

nrsharma
  • 2,532
  • 3
  • 20
  • 36
0

Replace you link button with this

<asp:LinkButton ClientIDMode="Static" ID="LinkButton3" runat="server">LinkButton</asp:LinkButton>

see this:

ClientIDMode="Static"

sangram parmar
  • 8,462
  • 2
  • 23
  • 47