Question

First off, yes I know I shouldn't be using frames, but I don't have a choice. It's an old system that's caused me nothing but headaches, but the network engineers love it and demand that this is where their information and pages have to go.

I'm currently using the .NET 4.0 framework, c#, and, though I doubt it matters for this question, SQL Server 2008R2.

The problem as it stands right now: I need a way to determine whether the primary or standby hardware is selected so I can properly set the radio button and initial information on page load to either the primary hardware or secondary hardware based on which page is loaded. The website my page is being used on is third party, which I do not have access to modifying, so I can't just tack URL variables onto that page or change settings.

The URL has variables, but they're generated statically elsewhere on the website and only visible inside the frame in which my page resides. I've never actually used frames, so I'm at a little bit of a loss. Worse, because of the way this is set up and being tested, I'm not actually sure how to set up any breakpoints in the code to see where it's failing.

I couldn't think of another way around this, but I would be more than happy to have a solution that doesn't involve this frame-y nonsense.

So far, I've been looking at these for guidance, but haven't had much success. sharing variables between urls and frames, msdn's .NET 4.0 page on Frames, a post on how to get url variables out of frames, and loading pages in IFrame dynamically from the codebehind.

For the time being, I've been asked to make sure the page as it stands does not break, which is why this is being checked instead of just done. It's currently in two places on that site, one without frames and URL variables (which the admins want to delete) and the new home with URL variables and frames. For now, the first one can't break, which is why you'll see a bit of strange checking and the ?? operator.

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                System.Web.UI.HtmlControls.HtmlGenericControl orionIFrame =
                        (System.Web.UI.HtmlControls.HtmlGenericControl)this.FindControl("pcmaframe");
                if (orionIFrame != null)
                {
                    string frameURL = orionIFrame.Attributes["src"].ToString() ?? "";

                    Uri frameURI = new Uri(frameURL);

                    NameValueCollection queryVars = HttpUtility.ParseQueryString(frameURI.Query);

                    //If this is in Orion, we want to change the canceller to standby if it's 97, not 96
                    if (queryVars["NetObject"] == "N:97" || queryVars["NetObject"] == "N%3a97")
                    {
                        SelectCanceller.SelectedValue = "Standby";
                        primaryStandby = false;
                    }
                }
//Do some other stuff to generate page data

Right now, the code that generates the frame looks like this (where [url] replaces the actual url and [mypage] replaces the actual file name I've used):

NodeID - ${NodeID}<br>
Node Name - ${NodeName}

<iframe id="pcmaframe" src="[url]/[mypage].aspx?NetObject=N:" + ${NodeID} width = 1000 height = 1500>
</iframe>

At the moment, there is no bad behavior, it simply fails to switch. Both pages display the primary, regardless of the URL variables. The primary being N:96 and the secondary being N:97. The reason I check is that I'd like it to display something in the event that it fails, so it defaults to the primary hardware.

So, wonderful Stack Overflow people... Can you answer any of my three questions?

  1. How can I troubleshoot a Frame on a separate website without adding output to the page when I have no way to insert breakpoints?

  2. What can I do instead of using the URL variables and messing with these frames?

  3. What logic am I missing or screwing up in my code that's causing the frame to /not/ recognize the URL variable?

UPDATE

Well, so far, I've determined that the frame is null. Not sure if this is because of the this.FindControl is not being properly cast, or it's due to the way the website uses frames, or any number of other things...

Was it helpful?

Solution

After being allowed to add some debugging output to the page, I was able to find a work around. What I believe is happening, based on some testing and these articles:

FindControl() return null

Better way to find control in ASP.NET

http://msdn.microsoft.com/en-us/library/txxbk90b%28v=vs.90%29.aspx

http://forums.asp.net/t/1097333.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.page.previouspage.aspx

Is that the website where my program/page is being used has the frame at a higher level than my ASP has access to without a lot of technical voodoo. Since the frame wasn't returning, I started testing and found that the calling frame was actually using [URL].[MyPage].aspx?NetObject=N:97 as the previous page or the calling page. This was true under a variety of circumstances which meant it was semi-safe to use Request.UrlReferrer:

protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {
        string frameURL = Request.UrlReferrer.ToString() ?? "NO DATA";

        if ((frameURL != null) && (frameURL != "NO DATA"))
        {

            Uri frameURI = new Uri(frameURL);

            NameValueCollection queryVars = HttpUtility.ParseQueryString(frameURI.Query);

            //If this is in Orion, we want to change the canceller to standby if it's 97, not 96
            if (queryVars["NetObject"] == "N:97" || queryVars["NetObject"] == "N%3a97")
            {
                SelectCanceller.SelectedValue = "Standby";
                primaryStandby = false;
            }
        }   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top