user516883
user516883

Reputation: 9378

asp HyperLink not working in jquery

for some reason only the asp.net hyperlink is not workin with jquery. Any suggestions?

<asp:HyperLink runat="server" ID="hypeDeleteBaseline" Text="Delete Baseline" /> <br/>

//Delete Baseline information
jQuery('[id$="hypeDeleteBaseline"]').click(function (e) {
    e.preventDefault();      
    var equipid = "<%=Equipment.ID%>";
    var inspectionid = jQuery('[id$="ddInspectionDate"]').val();
    deleteBaseline(equipid, inspectionid);
});

Thanks for any help.

Upvotes: 0

Views: 1682

Answers (3)

user516883
user516883

Reputation: 9378

Nothing was wrong with my code. The asp hyperlink was being loaded via jquery.load ajax call. so on the call back function for load i just added

jQuery('[id$="hypeDeleteBaseline"]').click(function (e) {
        e.preventDefault();      
        var equipid = "<%=Equipment.ID%>";
        var inspectionid = jQuery('[id$="ddInspectionDate"]').val();
        deleteBaseline(equipid, inspectionid);
    });

And now it works perfectly. Thanks for all suggestions.

Upvotes: 0

StriplingWarrior
StriplingWarrior

Reputation: 156459

Your selector is a little unusual. Have you tried:

jQuery('#hypeDeleteBaseline').click(...)

Also, have you checked the HTML that gets rendered? As often as not, the ID that you set on the control is not actually the ID that gets rendered in the HTML. Something like this might work:

jQuery('<%=hypeDeleteBaseline.ClientId%>').click(...)

Finally, you didn't include much context with your javascript class. Make sure it's inside a document-ready handler:

<script type="text/javascript">
    jQuery(function(){
        //Delete Baseline information
        //...
    });
</script>

Upvotes: 1

Aristos
Aristos

Reputation: 66641

You need to get the ClientId as rendered on html and not as parametre, try:

jQuery('#<%=hypeDeleteBaseline.ClientID%>')

or if you working with Net 4, set ClientIDMode="Static" on your HyperLink to not change the render id.

Upvotes: 0

Related Questions