问题描述:

I using this code below, and its operation is normal but when using with MasterPage its behavior has serious problems thecode not function.

/// script /////

$(".cssopen").click(function (e) {

//Cancel the link behavior

e.preventDefault();

//Get the A tag

//var id = $(this).attr('href');

//alterado

var id = '.window';

var body = $("html");

//Get the screen height and width

var maskHeight = $(document).height();

var maskWidth = $(window).width();

//Set height and width to mask to fill up the whole screen

$('#mask').css({ 'width': maskWidth, 'height': maskHeight });

//transition effect

$('#mask').fadeIn(1000);

$('#mask').fadeTo("slow", 0.8);

//Get the window height and width

var winH = $(window).height();

var winW = $(window).width();

//Set the popup window to center

$(id).css('top', winH / 2 - $(id).height() / 2);

$(id).css('left', winW / 2 - $(id).width() / 2);

//inserido

href = $(this).attr("href");

$('.window').load(href);

//transition effect

$(id).fadeIn(2000);

//$(id).show();

$(id).show().position({ my: "center", at: "center", of: "html" });

});

//if close button is clicked

$('.window .close').click(function (e) {

//Cancel the link behavior

e.preventDefault();

$('#mask, .window').hide();

});

//if mask is clicked

$('#mask').click(function () {

$(this).hide();

$('.window').hide();

});

/////////////// code .aspx //////////////////

<div>

<asp:ImageButton ID="imgBtCmd" runat="server" ImageUrl="~/Image/edit.png" href="frmIndexII.aspx" CssClass="cssopen"/>

</div>

网友答案:

I am not sure you have posted all the info required but i'm making an educated guess that you are grabbing controls by ID using jQuery and this has broken since introducing a master page. This is because the master page will change the client side id of the rendered HTML element.

If you are on .net4 and above you can use

<asp:SomeControl ClientIdMode="static">

And the controls will retain their Id client side. Alternatively you can add a class to your controls and jQuery them by class rather than ID.

相关阅读:
Top