OrElse
OrElse

Reputation: 9959

Simple, JQUERY: How can i show a popup window on hyperlink click?

My aspx markup is as

<div class="sm08" id="dialog" title="Dialog Title"><asp:Literal ID="litTerms" runat="server"></asp:Literal></div>

and

<asp:HyperLink ID="hp" runat="server" NavigateUrl="#">HyperLink</asp:HyperLink>

How can i load the popup on hyperlink click? Currently the popup is shown at page load.

<script type="text/javascript">
    $(document).ready(function () {
        $("#dialog").dialog({modal: true, buttons: { "Ok": function() { $(this).dialog("close"); } }});
    });
  </script>

Thank you in advance

Upvotes: 1

Views: 1779

Answers (2)

kevinpeterson
kevinpeterson

Reputation: 1172

Add a click listener to your link:

$('#hp').click(function(e){
   e.preventDefault();
   $('#dialog').dialog('open'); 
});

Also, you will want to set 'autoOpen' to 'false:

$("#dialog").dialog({autoOpen: false, modal: true, buttons: { "Ok": function() { $(this).dialog("close"); } }});

Upvotes: 1

Ram
Ram

Reputation: 144659

try this:

$(document).ready(function () {
    $('#hp').on('click', function(e){
       e.preventDefault() // prevents the default action of the anchor link
       $("#dialog").dialog({modal: true, buttons: { "Ok": function() { $(this).dialog("close"); } }});
    })
});

Upvotes: 1

Related Questions