Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4027564
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:06:44+00:00 2026-05-20T11:06:44+00:00

I have an aspx master/content page scenario. The parent page has an IFrame which

  • 0

I have an aspx master/content page scenario. The parent page has an IFrame which points to a child.aspx. The child.aspx has a checkbox, On page_load of child.aspx, I want to show/hide the checkbox depending on the following logic:
– if the child.aspx is opened directly, then I have to show the checkbox.
– if the child.aspx is opened in the IFrame, then I have to hide the checkbox.
Basically, I want to check in child.aspx, if it contains a parent window then hide the checkbox control otherwise show it.

I will prefer the show/hide code in codebehind in Page_load event as I have to execute some more logic depending on whether the it is opened from parent window or not.

Till now I did the following:
In 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>

in 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;
    }
}

Using RegisterClientScriptBlock, I get error in JS. That the object hfDoesParentExist doesn’t exist ‘coz the control is not yet created. Right? I tried using RegisterStartupScript but in codebehind I always get null in hidden variable. I don’t want to use the on button click or something like it. I need it on page_load event only. How to resolve the issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:06:44+00:00Added an answer on May 20, 2026 at 11:06 am

    This line:

    document.getElementById(HClientID).Value = bool;
    

    Should be: (lower case value)

    document.getElementById(HClientID).value = bool;
    

    Also you cannot check the value of a hidden field set by javascript register callback, in the current executing context on the server side.

    I would move the logic to the client side to hide or show the checkbox. If the field must indeed be removed from the page you can do that as well with javascript.

    function DoesParentExists()
    {
        var bool = (parent.location == window.location)? false : true;
        var cehckboxId ='<%=chkValid.ClientID%>'; 
        if(bool){ 
            document.getElementById(cehckboxId).style.display = 'none';
        }
        else {
            document.getElementById(cehckboxId).style.display = 'block';
        }
    }    
    

    You may want to wrap the checkbox with a div and hide the container also to include the label.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a content page which has a related master page. I register a
On my content page I have the code (in page_load): if (Master.pageAction == remove)
I have a master page called MasterPage.master which has a <fieldset> with a <legend>
I have an aspx page that uses a master page. On this page I
I have an ASPX page (On server A) which is invoked using NTLM credentials.
I have one aspx page with some controls. Also i have one DIV which
I have Default.aspx page, which inherits from BasePage.cs, which inherits from System.Web.UI.Page. BasePage is
I have a master page(MyMasterPage.master) with two content place holders. I wanna show another
Say I have a web site with a master page and an aspx page.
I have a MasterPage at Rool level. I have a content page: login.aspx -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.