2012-04-17 11 views
0

私はマスターページに基づいてasp.net 4 Webアプリケーションを持っています。マスターページ内で、スクリプトとcssファイルを参照しました。しかし、ページが読み込まれるとき、私はJavaScriptエラー 'Microsoft JScript実行時エラー:オブジェクトが期待されている'を取得しています。私はこれがマスターページと関係があることを知っています。なぜならマスターページなしでテストアプリケーションをビルドすれば、コードはうまく動作するからです。マスターページに基づいてasp.net Webアプリケーションで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 ContentPlaceHolder ID値+ '_' +チェックボックスのid値:ODE

<%@ 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に変換されます飛翔しました。チェックボックスのid値はContentPlaceHolder1_checkbox1です。マスターページを使用している間、すべてのIDがasp.netで変更されるように注意してください。 – Thulasiram

+0

これは期待していますか? – Thulasiram

+0

ブラウザで右クリックしてページソースを表示すると、チェックボックスの元のIDが表示されます。私もasp.net C#Webアプリケーションを使用してwebpageを使用してjqueryを実装するmasterpageと同じ問題に直面した。 – Thulasiram

関連する問題