wifi
wifi

Reputation: 13

jquery modal window in asp.net

I want to open default.aspx with jquery pop-up when I click on a button. But jquery modalwindow doesn't work. When I click the button default.aspx page opens directly.

Script:

<script type="text/javascript"> 
 $("#myElement").click(function (e) {
     e.preventDefault();
     $.get("Default.aspx", function (resp) {
         var data = $('<div></div>').append(resp);
         data.modal();
     });
 });
 </script>

Html:

<a id="myElement" href="">Linkler</a>

or

<a id="myElement" href="default.aspx">Linkler</a>

Upvotes: 0

Views: 1006

Answers (3)

Awad Maharoof
Awad Maharoof

Reputation: 2370

Its the <a> anchor tag with a href attribute thats opening your page directly.

You could use an input element like
<input type="button" id="myElement" value="click me">

Assuming you use JqueryUI, you could use this approach with a few modifications.

var path = "Default.aspx"; //path to your file

$("#myElement").click(function (e) {
    $("#somediv").load(path).dialog({
        modal: true
    });
});

I tried load an external page using a URL, but the browser security blocks it, but its possible to load a file with a relative path.

Dont forget to include Jquery and JqueryUI (and Jquery css too if required) in your page.

Upvotes: 2

Jopay
Jopay

Reputation: 21

You can use some plugins. This really can help you and its easy change someting.

Upvotes: 0

GvM
GvM

Reputation: 1733

There is no .modal() in jQuery. The correct call would be:

data.dialog({
    modal: true });

And this is using jQueryUI so make sure to be referencing that library as well.

Check out the API docs for more info on dialog: http://api.jqueryui.com/dialog/

Upvotes: 0

Related Questions