0

I have a parent page containing an iframe, an ASP label and a button. When the user click on the parent button, it will display some table results inside the iframe. Now i would like to display the parent label with different text and color depending on the results of the iframe. So i m trying in the code behind (C#) of the iframe to retrieve the label from the parent and assign it a CssClass. But no matter what i do it always come back with a null reference when trying to find the control from the parent. Can someone please help?

Parent page code:

<div class="search-row">
  <div class="search">
      <button id="btnSearch" type="submit" class="button button-block">Search</button>
  </div>

  <div class="search" style="padding-top: 20px;">
        <asp:Label ID="wrapperResponse" CssClass="resp" runat="server">TEST</asp:Label>
   </div>
</div>


        <div id="iframeDiv">
            <iframe name="my_frame" width="100%" height="350px" src="Results.aspx" scrolling="no" frameborder="0"></iframe>
        </div>`

The Results.aspx will display a table with some html build dynamically. Now let s say if resulting Table has one row, i would like Label WrapperReponse to be in Green and says "1 row" but if 2 rows then i would like it to be in Red and says "2 Rows"

In my Results.aspx.cs i tried

    String test= String.Format("{0}", Request.Form["wrapperResponse"]);
    Label statusResponse = (Label)this.FindControl("wrapperResponse");
    Label statusResponse2 = (Label)Parent.FindControl("wrapperResponse");

Any ideas are welcome! thanks

Mélanie
  • 31
  • 2
  • 10

1 Answers1

0

Well, just a couple of points needed mentioning here. Food for thought.

  1. In order to access the asp label control, you need to do it on the parent page instead of on the results page.
  2. I would suggest you reconsider the design of the page. Do you really have to use the iframe here? Why not place your button and label controls on the results.page directly? Or perhaps make results.aspx as an ASCX user control, so you can embed it on the parent page.

Hope it helps

woodykiddy
  • 6,074
  • 16
  • 59
  • 100