aspxマスター/コンテンツページのシナリオがあります。親ページには、child.aspxを指すIFrameがあります。child.aspxにはチェックボックスがあります。child.aspxのpage_loadで、次のロジックに応じてチェックボックスを表示/非表示にします。-child.aspxを直接開いた場合は、チェックボックスを表示する必要があります。--child.aspxがIFrameで開かれている場合は、チェックボックスを非表示にする必要があります。基本的に、child.aspxをチェックインしたいのですが、親ウィンドウが含まれている場合はチェックボックスコントロールを非表示にし、そうでない場合は表示します。
親ウィンドウから開いているかどうかに応じてさらにロジックを実行する必要があるため、Page_loadイベントのコードビハインドでコードを表示/非表示にすることをお勧めします。
今まで私は次のことをしました:child.aspxで
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
<script language="javascript" type="text/javascript">
function DoesParentExists()
{
var bool = (parent.location == window.location)? false : true;
var HClientID ='<%=hfDoesParentExist.ClientID%>';
document.getElementById(HClientID).Value = bool;
}
</script>
<div>
<h2>Content - In IFrame</h2>
<asp:HiddenField runat="server" id="hfDoesParentExist" />
<asp:CheckBox ID="chkValid" runat="server" />
<asp:ImageButton ID="ImageButton_FillW8Online" ImageUrl="~/images/expand.gif"
OnClick="btnVerify_Click" runat="server" style="height: 11px" />
</div>
</asp:Content>
client.aspx.csで
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "DoesParentExists", "DoesParentExists()", true);
if (hfDoesParentExist.Value == "true")
{
chkValid.Visible = false;
}
}
RegisterClientScriptBlockを使用すると、JSでエラーが発生します。オブジェクトhfDoesParentExistが存在しないこと'cozコントロールはまだ作成されていません。右?RegisterStartupScriptを使用してみましたが、コードビハインドでは、隠れた変数で常にnullが発生します。オンボタンクリックなどは使いたくない。page_loadイベントでのみ必要です。問題を解決する方法は?