2012-04-17 2 views
0

마스터 페이지를 기반으로하는 asp.net 4 웹 응용 프로그램이 있습니다. 마스터 페이지에서 필요한 스크립트와 CSS 파일을 참조했습니다. 그러나 페이지가로드 될 때 JavaScript 오류 'Microsoft JScript 런타임 오류 : 개체가 예상됩니다.'가 표시됩니다. 마스터 페이지없이 테스트 응용 프로그램을 작성하면 코드가 정상적으로 작동하기 때문에 이것이 마스터 페이지와 관련이 있다는 것을 알고 있습니다.마스터 페이지를 기반으로 asp.net 웹 응용 프로그램에서 JQuery를 사용하여 팝업 창을 엽니 다.

마스터 페이지 코드

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication2.Site1" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"> 
    <script src="Popup.js" type="text/javascript"></script> 
    <link rel="stylesheet" href="StyleSheet1.css" type="text/css" media="screen" /> 
    <script type="text/javascript" src="jquery-1.7.1.min.js"></script> 
    <title>Test</title> 
    <asp:ContentPlaceHolder ID="head" runat="server"> 
    </asp:ContentPlaceHolder> 
    </head> 
    <body> 
     <form id="form1" runat="server"> 
    <div> 
     <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
     </asp:ContentPlaceHolder> 
    </div> 
    </form> 
    </body> 
    </html> 

팝업 코드

function Popup() { 
     window.showModalDialog("webForm3.aspx", ""); 
    } 

$(document).ready(function() { 
    $("#button").click(function() { 
     var isChecked = $('#checkbox1').is(':checked'); 
     if (isChecked) { 
      Popup(); 
     } 
    }); 
}); 

메인 페이지 코드

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" 
CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
Check box 
    <div id="button"> 
     <asp:CheckBox ID="checkbox1" runat="server" /></div> 
</asp:Content> 

팝업 페이지 C 송시

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs"  Inherits="WebApplication2.WebForm3" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0  Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>Popup</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> 
Hellow World 
</div> 
</form> 
</body> 
</html> 

답변

0
//================ site1.master =======================// 

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="site1.master.cs" Inherits="NewJqueryPlugins.site1" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> 
    <script src="Popup.js" type="text/javascript"></script> 
    <asp:ContentPlaceHolder ID="head" runat="server"> 
    </asp:ContentPlaceHolder> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
     </asp:ContentPlaceHolder> 
    </div> 
    </form> 
</body> 
</html> 

//================ popup.js =======================// 


$(document).ready(function() { 
    $('#button').click(function (e) { 
     //var isChecked = $(this).find('#ContentPlaceHolder1_checkbox1').is(':checked'); 

     //Or 

     var isChecked = $(this).find(':checkbox').is(':checked'); 

     if (isChecked) { 
      Popup(); 
     } 
    }); 
}); 

function Popup() { 
    window.showModalDialog("webForm3.aspx", ""); 
}; 


//================ webfrom2.aspx =======================// 


<%@ Page Title="" Language="C#" MasterPageFile="~/site1.Master" AutoEventWireup="true" 
    CodeBehind="WebForm2.aspx.cs" Inherits="NewJqueryPlugins.WebForm2" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
    <div id="button" style="border: 2px solid green;"> 
     Check box 
     <asp:CheckBox ID="checkbox1" runat="server" /> 
    </div> 
</asp:Content> 


//================ webfrom3.aspx =======================// 


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="NewJqueryPlugins.WebForm3" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Popup</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     Hellow World 
    </div> 
    </form> 
</body> 
</html> 
+0

모든 입력이 ID가 ASP로 변환됩니다 날아 마스터 페이지 사용하는 경우의 ContentPlaceHolder id 값 + '_'+ 체크 박스의 id 값을. 이제 체크 박스의 id 값은 ContentPlaceHolder1_checkbox1입니다. 그래서 마스터 페이지를 사용하여 신중하게 모든 ID가 asp.net에서 변경됩니다. – Thulasiram

+0

예상치 못한 결과가 나올까요? 브라우저에서 – Thulasiram

+0

을 마우스 오른쪽 버튼으로 클릭하고 페이지 소스를 보려면 체크 박스의 원래 ID를 볼 수 있습니다. 나는 또한 asp.net C# 웹 응용 프로그램 masterpage를 사용하여 webform jquery 구현에 대한 작업 할 때 동일한 문제에 직면했다. – Thulasiram

관련 문제