FathiAlqadasi FathiAlqadasi - 2 years ago 121
ASP.NET (C#) Question

jQuery div dialog open in the same page

I used jQuery div dialog to show new user page as show in picture

http://www.4shared.com/photo/VGtCVSkv/newuser.html

But when I press save button the new userpage is opening in the same page as show in the picture

http://www.4shared.com/photo/T_wkDnMG/savenew.html

Markup:

<ul class="menu" style="margin-left:10px; background-color:transparent; width:100%;">
<li>
<input type="button" ID="btnNew" value="Add New" style="background-color:transparent; border:0;" runat="server" />
</li>
</ul>


Code-Behind:

btnNew.Attributes.Add("onClick", "ShowEntityEditor('NewUser.aspx','userID',0,'New User',300,650);")


JavaScript: (placed in the master page)

function ShowEntityEditor(url, pname, entityID, txttitle, h, w) {
var _editWindowDiv;
_editWindowDiv = $("#_editWindowDiv").dialog({
autoOpen: false,
height: h,
width: w,
position: 'center',
title: txttitle
});
_editWindowDiv.empty();
_editWindowDiv.load(url + "?" + pname + "=" + entityID, function () {
$("#cancelButtoon").click(function () {
_editWindowDiv.dialog("close");
return false;
});
});
_editWindowDiv.dialog("open");
}

Answer Source

in the newUser.aspx page use the following code to prevent the page form being submitted. submit newUser.aspx will close the dialog and redirect to the page.

   <script>
   $("#userForm").submit(function(e){
       e.preventDefault();
     });
   </script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download