question about using an iframe

I am using a repeater to display a series of hyperlinks on a page.  The repeater is pulling the data dynamically from a database.  The url field in the database contains an absolute path to a page located externally from our company site.  So, currently, when my page renders and you click on one of the links it redirects to this external page.

What I have been asked to do is keep the external page within our company site, so it maintains the look and feel of our site and doesn't look like it is going to an entirely different application, which of course it is.

Is there a way to do this with an iframe or some other way to accomplish this?  Any examples would be helpful.

See the code below.

Thanks for any help.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Welcome!</h3>

        <p>What's it like to work at CompassLearning?</p> 
        
        <p>
        Picture a learning studio of highly educated curriculum experts in science, math, English, social sciences, and other fields working alongside 
        animators, scriptwriters, and engineers. At CompassLearning, we don't just recognize and reward talent-we develop and nurture it. By merging the 
        skills and experiences of our employees with a dynamic environment that values innovation, we make this a place where people genuinely enjoy 
        working together as a team. 
        </p>

        <p>
        CompassLearning is an equal opportunity employer. We do not discriminate in hiring and employment on the basis of race, color, religion, 
        national origin, citizenship, gender, marital status, sexual orientation, age, physical or mental disability, veteran status, or any other 
        characteristic protected by federal, state, or local law. 
        </p>
        
        <p>
        If you want to work with a group of forward-thinking leaders who bring passion and enthusiasm to work every day, we invite you to search our 
        CompassLearning Current Listings below and apply online. 
        </p>
        
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="JobsObjectDataSource">
            <HeaderTemplate>
                <ul>
            </HeaderTemplate>
            <ItemTemplate>
                <li><a href='<%# Eval("URL") %>'><%# Eval("JobTitle") %></a></li>
                <%# Eval("City") %>, <%# Eval("State") %>, <%# Eval("Country") %><br /><br />
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
        <asp:ObjectDataSource ID="JobsObjectDataSource" runat="server" 
            OldValuesParameterFormatString="original_{0}" SelectMethod="GetJobs" 
            TypeName="ADPLibrary.BLL.JobBLL"></asp:ObjectDataSource>
    
    </div>
    </form>
</body>
</html>

Open in new window

-Dman100-Software ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Akin DeluI’m a software engineer, tech enthusiast and UI/UX lover. Commented:
Note calling an external url will not inherit your own pre-difine styles.
0
intlaqaCommented:
Yeah, just replace your <a> tag with a LinkButton and add an iframe which runs at sever, for example:

<asp:Repeater ID="Repeater1" runat="server"
            onitemcommand="Repeater1_ItemCommand">
            <HeaderTemplate>
                <ul>
            </HeaderTemplate>
            <ItemTemplate>
                <li><asp:LinkButton CommandName="UrlClicked" CommandArgument='<%# Eval("URL") %>' ID="lbtnJob" runat="server"><%# Eval("JobTitle") %></asp:LinkButton></li>
                <%# Eval("City") %>, <%# Eval("State") %>, <%# Eval("Country") %><br /><br />
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
       
        <iframe runat="server" id="myIframe" src="" width="200" height="200"></iframe>

Then on the codebehind, handle the ItemCommand event to change the iframe src attribute to the clicked url:

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "UrlClicked")
        {
            myIframe.Attributes["src"] = e.CommandArgument.ToString();
        }
    }

akindelu is correct, the iframe won't inherit your website style, but, actually you can write some code in the ItemCommand to get the HTML of the page you want to render, split it, replace some stuff in it and put it in a Literal control (Screen-Scraping).

For example, add a Literal instead of the iframe, and add this code to the ItemCommand:


protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "UrlClicked")
        {
            HttpWebRequest myExternalRequest = (HttpWebRequest)HttpWebRequest.Create(e.CommandArgument.ToString());

            HttpWebResponse myExternalResponse = (HttpWebResponse)myExternalRequest.GetResponse();

            StreamReader externalPageReader = new StreamReader(myExternalResponse.GetResponseStream());

            string externalPageHtml = externalPageReader.ReadToEnd();

            externalPageReader.Close();
            myExternalResponse.Close();

            // Write some code which removes the <html><head>... etc from externalPageHtml to just make only have the html you want from the external source


            myLitral.Text = externalPageHtml;
        }
    }

Open in new window

0
-Dman100-Software ConsultantAuthor Commented:
Hi intlaga,

Thanks for the help.  You're suggestion worked it my development environment just fine.  However, when I went to update the code on our staging server, for some reason the Repeater1_ItemCommand event handler is not firing.  I put a breakpoint on that event handler and debugged.  When I click the Linkbutton, the page refreshes and never enters the ItemCommand event handler.  This is the first time I've encountered this?  I don't know how to debug this?  Any idea what would cause the ItemCommand event handler to not fire?  Everything looks like it is wired correctly.  I'm using the exact same code that I'm using in my development environment and it runs fine there.  I'm perplexed?

Thanks again!
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

intlaqaCommented:
Hi,

This is strange, could you please show me your Page_Load event, perhaps it contains some code which should be in if(!IsPostBack) .. etc, it is common.

Also are you sure you made a 'Rebuild All' and published your website successfully (Including your BIN and the Page) ?
0
-Dman100-Software ConsultantAuthor Commented:
I don't have any code in the Page_Load event handler.  It is empty.

I did a fresh build, but still the same result.  I don't know what is going on?  Is there a way to debug this?
0
-Dman100-Software ConsultantAuthor Commented:
I added a breakpoint on the Page_Load event and when I click on the linkbutton in the page, it goes right into the page load.  It never raises the OnItemCommand event handler.  I have no idea why this is happening or how to debug it.  I stepped into everything and it just goes right into Page_Load like there is not an OnItemCommand event handler.

I'm totally at a loss.
0
intlaqaCommented:
Hi,

Do you use the same repeater code I wrote? if you changed it could you please show it to me and the ItemCommand event handler code.

Be sure that CommandName="UrlClicked" in the LinkButton in the repeater. And be sure that onitemcommand="Repeater1_ItemCommand" in the repeater as well.

How do you bind the repeater, are you still using the ObjectDataSource? or you bind it somewhere else by code dynamically?

Try to remove the ObjectDataSource and DataSourceId and bind the repeater in Page_Load:

if(!IsPostBack)
{
Repeater1.DataSource = ADPLibrary.BLL.JobBLL.GetJobs();
Repeater1.DataBind();
}

Should me your code again if you can.
0
-Dman100-Software ConsultantAuthor Commented:
Hi intlaga,

Yes, I used the same repeater code you used.  I am using an ObjectDataSource to bind to the repeater.  I tried removing the ObjectDataSource and bind in the Page_Load as you indicated.  I got the following error:

The type 'System.Data.TypedTableBase`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I've included the code in the aspx and code-behind below.  Do you see anything incorrect?

Thanks for your help.
aspx page:

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" 
    CodeFile="ExternalJobOpp.aspx.cs" Inherits="About_ExternalJobOpp" Title="Career Opportunities" %>
<%@ Register TagName="SidebarContact" TagPrefix="uc" Src="~/Controls/SidebarContact.ascx" %>
<%@ Register TagName="SidebarQuote" TagPrefix="uc" Src="~/Controls/SidebarQuote.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    <div id="content-sidebar">
        <!-- open sidebar -->
        <div class="sidebar-nav">
            <div class="sbnav-bottom">
                <div class="sbnav-top">
                    <!-- nav-about -->
                    <ul class="multilevel">
                       <li class="tl-first-flat"><a class="tl-first-flat" href="Management.aspx" title="Management Team">Management Team</a></li><li class="tl-flat"><a class="tl-flat" href="Awards.aspx" title="Awards">Awards</a></li><li class="tl-flat"><a class="tl-flat" href="CustomerQuotes.aspx" title="Customer Quotes">Customer Quotes</a></li><li class="tl-flat"><a class="tl-flat" href="Partners.aspx" title="Partners &amp; Alliances">Partners &amp;
                            Alliances</a></li><li class="tl-last-active"><a class="tl-last-active" href="ExternalJobOpp.aspx" title="Careers">Careers</a>
                            <ul class="level-one">
                                <li class="first"><a href="Contract.aspx" title="Contract Opportunities">Contract Opportunities</a></li></ul>
                        </li>
                    </ul>
                    <!-- /nav-about -->
                </div>
            </div>
        </div>
        <uc:SidebarContact ID="SidebarContact1" runat="server" />
        <uc:SidebarQuote ID="sidebarQuote" runat="server" />
    </div>
    <!-- close sidebar -->
    <div id="content-primary">
        <div id="primary-top">
            <div id="primary-bottom">
                <!-- open primary -->
                <div class="primary-text">
                    <h1>Careers</h1>
                </div>
                <div class="primary-text">
                    <!-- open primary-text -->
                    
                    <p>What's it like to work at CompassLearning?</p> 
        
                    <p>
                    Picture a learning studio of highly educated curriculum experts in science, math, English, social sciences, and other fields working alongside 
                    animators, scriptwriters, and engineers. At CompassLearning, we don't just recognize and reward talent-we develop and nurture it. By merging the 
                    skills and experiences of our employees with a dynamic environment that values innovation, we make this a place where people genuinely enjoy 
                    working together as a team. 
                    </p>

                    <p>
                    CompassLearning is an equal opportunity employer. We do not discriminate in hiring and employment on the basis of race, color, religion, 
                    national origin, citizenship, gender, marital status, sexual orientation, age, physical or mental disability, veteran status, or any other 
                    characteristic protected by federal, state, or local law. 
                    </p>
        
                    <p>
                    If you want to work with a group of forward-thinking leaders who bring passion and enthusiasm to work every day, we invite you to search our 
                    CompassLearning Current Listings below and apply online. 
                    </p>
                    
                    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="JobsObjectDataSource" OnItemCommand="Repeater1_ItemCommand1">
                        <HeaderTemplate>
                            <ul>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <li><asp:LinkButton CommandName="UrlClicked" CommandArgument='<%# Eval("URL") %>' ID="lbtnJob" runat="server"><%# Eval("JobTitle") %></asp:LinkButton></li>
                            <p style="text-indent:15px;font-size:small;"><%# Eval("City") %>, <%# Eval("State") %>, <%# Eval("Country") %></p>
                        </ItemTemplate>
                        <FooterTemplate>
                            </ul>
                        </FooterTemplate>
                    </asp:Repeater>
                    <asp:ObjectDataSource ID="JobsObjectDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
                        SelectMethod="GetJobs" TypeName="ADPLibrary.BLL.JobBLL"></asp:ObjectDataSource>
                    
                    
                        
                    <iframe runat="server" id="myIframe" src="" width="650" height="450" frameborder="0"></iframe>
                </div>
                <!-- close primary-text -->
            </div>
            <!-- close primary-text -->
        </div>
    </div><!-- close primary -->
</asp:Content>


aspx.cs :: code-behind:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class About_ExternalJobOpp : System.Web.UI.Page
{
    public SiteMasterPage MPage
    {
        get { return (SiteMasterPage)Master; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    
    }

    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        MPage.SetActiveTab("about");
    }

    protected void Repeater1_ItemCommand1(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "UrlClicked")
        {
            myIframe.Attributes["src"] = e.CommandArgument.ToString();
        }
    }
}

Open in new window

0
intlaqaCommented:
Hi,

Could you please comment the following line on Page_LoadComplete and try again:

// MPage.SetActiveTab("about");

And please show me the code in the Master Page, specially that SetActiveTab function and the Page_Load, I think there is something reloads the page twice
0
-Dman100-Software ConsultantAuthor Commented:
Hi intlaga,

You are definitely correct, the problem has something to do with the master page.  I created a test page without the master and it works fine.  As soon as I attach the master page, it bombs.

I commented out the line:
// Mpage.SetActiveTab("about"); but it still tanks on me.

I have included the master page code below (sorry about the lengthy code)


site.master:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMasterPage" %>
<!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" xml:lang="en" lang="en">
<head id="Head1" runat="server" enableviewstate="false">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
    <title>CompassLearning</title>
    <meta name="description" content="CompassLearning is an award-winning educational software company based in Austin, Texas" />
    <meta name="keywords" content="compasslearning, compass learning, education, educational, software, products, odyssey, interactive, learn, learning, school, parents, teachers, students, pre-k, elementary, middle, high, research, results, austin, texas" />
    <link rel="shortcut icon" href="images/favicon.ico" />
    <!-- Stylesheets -->
    <link rel="stylesheet" type="text/css" href="style/default.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="style/print.css" media="print" />
    <!--[if IE 6]><link rel="stylesheet" type="text/css" href="style/IEdefault.css" media="screen" /><![endif]-->
    <script src="http://munchkin.marketo.com/js/munchkin.js" type="text/javascript"></script>
    <script type="text/javascript">mktoMunchkin("685-BIC-949");</script>
    <!-- www.hitslink.com/ web tools statistics hit counter code -->
    <script type="text/javascript" id="wa_u"></script>
    <script type="text/javascript">
    //<![CDATA[
    wa_account="EleanorBowman"; wa_location=31;
    wa_pageName=location.pathname;  // you can customize the page name here
    document.cookie='__support_check=1';wa_hp='http';
    wa_rf=document.referrer;wa_sr=window.location.search;
    wa_tz=new Date();if(location.href.substr(0,6).toLowerCase()=='https:')
    wa_hp='https';wa_data='&an='+escape(navigator.appName)+ 
    '&sr='+escape(wa_sr)+'&ck='+document.cookie.length+
    '&rf='+escape(wa_rf)+'&sl='+escape(navigator.systemLanguage)+
    '&av='+escape(navigator.appVersion)+'&l='+escape(navigator.language)+
    '&pf='+escape(navigator.platform)+'&pg='+escape(wa_pageName);
    wa_data=wa_data+'&cd='+
    screen.colorDepth+'&rs='+escape(screen.width+ ' x '+screen.height)+
    '&tz='+wa_tz.getTimezoneOffset()+'&je='+ navigator.javaEnabled();
    wa_img=new Image();wa_img.src=wa_hp+'://counter.hitslink.com/statistics.asp'+
    '?v=1&s='+wa_location+'&acct='+wa_account+wa_data+'&tks='+wa_tz.getTime();
    document.getElementById('wa_u').src=wa_hp+'://counter.hitslink.com/track.js'; //]]>
    </script>
    <!-- End www.hitslink.com/ statistics web tools hit counter code -->
</head>
<script type="text/javascript" language="JavaScript" src="/elqNow/elqCfg.js"></script>
<script type="text/javascript" language="JavaScript" src="/elqNow/elqImg.js"></script>
<script type="text/javascript" language="JavaScript">
<!--//
var elqPPS = '70';
//-->
</script>
<script type="text/javascript" language="JavaScript" src="/elqNow/elqScr.js"></script>
<script type="text/javascript" language="JavaScript">
<!--//
window.onload = initPage;
function initPage(){
    if (this.GetElqCustomerGUID)
        document.forms[0].elements["elqCustomerGUID"].value = GetElqCustomerGUID();
}
//-->
</script>
<body id="body" class="<%= BodyClass %>">
    <form id="pageForm" runat="server" enableviewstate="false">
    <div id="wrapper" class="<%= HeroClass %>">
        <div id="header">
            <div id="header-logo">
                <asp:HyperLink ID="linkIndex" runat="server" EnableViewState="false" NavigateUrl="~/Default.aspx" ToolTip="CompassLearning Home Page" />
            </div>
            <div id="header-clientnav">
                <a href="http://www.compasslearningodyssey.com/" target="_blank" title="Odyssey Online">Odyssey Online &gt;</a> <a href="http://www.compasslearning.com/customersite/default.aspx" title="Customer Site">Customer Site &gt;</a>
            </div>
            <div id="header-controlbar">
                <div id="controlbar-nav">
                    <ul id="nav-global">
	                    <li class="first"><asp:HyperLink ID="linkHome" runat="server" EnableViewState="False" NavigateUrl="~/Default.aspx" ToolTip="Home">Home</asp:HyperLink></li>
	                    <li><asp:HyperLink ID="linkProducts" runat="server" EnableViewState="false" NavigateUrl="~/Products/Default.aspx?page=Products" ToolTip="Solutions">Solutions</asp:HyperLink></li>
	                    <li><asp:HyperLink ID="linkServices" runat="server" EnableViewState="false" NavigateUrl="~/services/Default.aspx?page=3.0.0" ToolTip="Services">Services</asp:HyperLink></li>
	                    <li><asp:HyperLink ID="linkNews" runat="server" EnableViewState="false" NavigateUrl="~/News/Default.aspx" ToolTip="News &amp; Events">News &amp; Events</asp:HyperLink></li>
	                    <li><asp:HyperLink ID="linkAbout" runat="server" EnableViewState="false" NavigateUrl="~/About/Default.aspx?page=About" ToolTip="About Us">About</asp:HyperLink></li>
	                    <li class="last"><asp:HyperLink ID="linkContact" runat="server" EnableViewState="false" NavigateUrl="~/Contact/Default.aspx" ToolTip="Contact Us">Contact</asp:HyperLink></li>
                    </ul>
                 </div>
                 <div id="controlbar-state-lookup"><span>STATE:</span>
                    <asp:DropDownList 
		                ID="state"   
		                CssClass="text"
		                runat="server" 
		                DataTextField="State_Abr" 
		                DataValueField="State_Abr" 
		                AutoPostBack="true"
		                EnableViewState="true"
		                OnSelectedIndexChanged="state_SelectedIndexChanged">
		                </asp:DropDownList>
                 </div>
                <div id="controlbar-search">                                 
                        <asp:TextBox ID="SearchText" runat="server" CssClass="text search-text" Text="Enter search terms" ToolTip="Enter search terms" />
                        <asp:ImageButton 
                            ID="searchButton" 
                            runat="server" 
                            ToolTip="Submit Your Search" 
                            ImageUrl="~/images/button-header-search.gif" 
                            AlternateText="Submit" 
                            CssClass="search-button" 
                            EnableTheming="False" 
                            EnableViewState="False" 
                            OnClick="SearchButton_Click" />
                </div>
            </div>
        </div>
        
        <div id="content">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
            <div id="footer" class="<%=FooterClass%>">
                <div id="footer-copyright">
                    <p>&copy; <%=DateTime.Now.Year %> CompassLearning</p>
                </div>
                <div id="footer-navigation">
                    <ul>
                        <li><asp:HyperLink ID="linkPrivacy" runat="server" EnableViewState="false" NavigateUrl="~/Privacy.aspx" ToolTip="Privacy Policy">Privacy Policy</asp:HyperLink></li>
                        <li><asp:HyperLink ID="linkSitemap" runat="server" EnableViewState="false" NavigateUrl="~/Sitemap.aspx" ToolTip="Site Map">Site Map</asp:HyperLink></li>
                    </ul>
                </div>
            </div>
        </div>
      </div>
   </form>
</body>
</html>

site.master.cs:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;

public partial class SiteMasterPage : System.Web.UI.MasterPage
{
    #region Fields

    private string _heroClass;
    private string _bodyClass = string.Empty;
    private string _activeTab;
    private string _searchResults;
    private string _footerClass = "";
    private Dictionary<string, HyperLink> _tabLinks = new Dictionary<string, HyperLink>();

    #endregion

    #region Properties

    public string HeroClass
    {
        get { return _heroClass; }
        set { _heroClass = value; }
    }

    public string ActiveTab
    {
        get { return this._activeTab; }
        set { this._activeTab = value; }
    }

    public string SearchResults
    {
        get { return _searchResults; }
        set { _searchResults = value; }
    }

    public string BodyClass
    {
        get { return _bodyClass; }
        set { _bodyClass = value; }
    }

    public HyperLink LinkHome
    {
        get { return this.linkHome; }
    }
    public HyperLink LinkProducts
    {
        get { return this.linkProducts; }
    }
    public HyperLink LinkServices
    {
        get { return this.linkServices; }
    }
    public HyperLink LinkNews
    {
        get { return this.linkNews; }
    }
    public HyperLink LinkAbout
    {
        get { return this.linkAbout; }
    }
    public HyperLink LinkContact
    {
        get { return this.linkContact; }
    }

    public DropDownList MicroSiteState
    {

        get { return state; }

        set { state = value; }

    }


    #endregion

    #region Methods

    public string FooterClass
    {
        get { return this._footerClass; }
        set { this._footerClass = value; }
    }

    protected void Page_Init(object sender, EventArgs e)
    {
        AddTabLinks();
        SetRandomHero();
        BindStates();

        if (Request["st"] != null)
        {
            state.SelectedIndex = state.Items.IndexOf(state.Items.FindByText(Request["st"].ToString().ToUpper()));
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        // Define the name, type and url of the client script on the page.

        String _swfObject = "SWFObjectScript";
        //String _mootools = "MooTools";
        String _utility = "Utility";
        String _utm = "UTM";
        String swfObjectUrl = "~/js/swfobject.js";
        //String mootoolsUrl = "~/js/mootools-release-1.11.js";
        String utilityUrl = "~/js/utility.js";
        String utmUrl = "~/js/__utm.js";
        Type cstype = this.GetType();

        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = Page.ClientScript;

        // Check to see if the include script exists already.
        if (!cs.IsClientScriptIncludeRegistered(cstype, _swfObject))
        {
            cs.RegisterClientScriptInclude(cstype, _swfObject, ResolveClientUrl(swfObjectUrl));
        }
        //if (!cs.IsClientScriptIncludeRegistered(cstype, _mootools))
        //{
        //    cs.RegisterClientScriptInclude(cstype, _mootools, ResolveClientUrl(mootoolsUrl));
        //}
        if (!cs.IsClientScriptIncludeRegistered(cstype, _utility))
        {
            cs.RegisterClientScriptInclude(cstype, _utility, ResolveClientUrl(utilityUrl));
        }
        if (!cs.IsClientScriptIncludeRegistered(cstype, _utility))
        {
            cs.RegisterClientScriptInclude(cstype, _utm, ResolveClientUrl(utmUrl));
        }

        if (!Page.IsPostBack)
        {
        }
    }

    protected void state_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (state.SelectedItem.Text != "Select")
        {
            Response.Redirect(ResolveUrl("~/States/Default.aspx?st=" + state.SelectedItem.Text));
        }
    }

    protected virtual void AddTabLinks()
    {
        AddTabLink("home", LinkHome);
        AddTabLink("products", LinkProducts);
        AddTabLink("services", LinkServices);
        AddTabLink("news", LinkNews);
        AddTabLink("about", LinkAbout);
        AddTabLink("contact", LinkContact);
    }

    protected void AddTabLink(string tabName, HyperLink link)
    {
        tabName = tabName.ToLower();
        if (!this._tabLinks.ContainsKey(tabName))
        {
            _tabLinks.Add(tabName, link);
        }
        else
        {
            _tabLinks[tabName] = link;
        }
    }

    public void SetActiveTab(string tabName)
    {
        HyperLink active = GetTabLink(tabName);
        foreach (HyperLink link in GetTabLinks())
        {
            if (link == active)
                link.CssClass = "active";
            else
                link.CssClass = string.Empty;
        }
        this._activeTab = tabName;
    }

    public IEnumerable<HyperLink> GetTabLinks()
    {
        HyperLink[] links = new HyperLink[_tabLinks.Count];
        _tabLinks.Values.CopyTo(links, 0);
        return links;
    }

    public HyperLink GetTabLink(string tabName)
    {
        tabName = tabName.ToLower();
        HyperLink result;
        if (_tabLinks.TryGetValue(tabName, out result))
            return result;
        else
            return null;
    }

    public void SetRandomHero()
    {
        if (SiteMap.CurrentNode == SiteMap.RootNode)
            HeroClass = Heros.GetRandomIndexHeroClass();
        else
        {
            //SiteMapNode c = SiteMap.CurrentNode;

            //SiteMapNode e = SiteMap.Provider.FindSiteMapNode(ResolveUrl("~/Products/Show?page=2.1.0"));
            //SiteMapNode m = (e != null)? e.NextSibling : null;
            //SiteMapNode h = (m != null) ? m.NextSibling : null;

            //if (c == e || c.IsDescendantOf(e))
            //  SetRandomHeroElem();
            //else if (c == m || c.NextSibling.IsDescendantOf(m))
            //  SetRandomHeroMiddle();
            //else if (c == h || c.NextSibling.IsDescendantOf(h))
            //  SetRandomHeroHigh();
            //else
            HeroClass = Heros.GetRandomHeroClass();
        }
    }
    public void SetRandomHeroElem()
    {
        HeroClass = Heros.GetRandomHeroClass(Heros.HeroGrade.Elem);
    }
    public void SetRandomHeroMiddle()
    {
        HeroClass = Heros.GetRandomHeroClass(Heros.HeroGrade.Middle);
    }
    public void SetRandomHeroHigh()
    {
        HeroClass = Heros.GetRandomHeroClass(Heros.HeroGrade.High);
    }
    public void BindStates()
    {
        DataTable dt = CompassLearning.DAL.MicroSiteDAO.GetAllMicroSites();
        ListItem li = new ListItem();

        foreach (DataRow dr in dt.Rows)
        {
            if (dr["State_Abr"].ToString() == "OT")
            {
                //Hack to show "Other" for International listings
                li.Text = dr["State_Abr"].ToString() + "HER";
                li.Value = dr["State_Abr"].ToString();
            }
            else
            {
                state.Items.Add(new ListItem(dr["State_Abr"].ToString(), dr["State_Abr"].ToString()));
            }
        }
        state.Items.Insert(0, new ListItem("Select", ""));

        if (li.Value != "") state.Items.Add(li);
    }

    protected void Search()
    {
        //string recherche = "";
        //recherche = SearchText.Text.Trim();

        //string address = "http://172.16.16.92/search?site=default_collection&proxystylesheet=my_frontend&proxyreload=1&client=my_frontend&output=xml_no_dtd&ip=172.16.16.92&";
        //address += "q=" + HttpUtility.UrlEncode(recherche);

        ////http request creation which will be send to the Mini
        //HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(address);

        ////All request are from GET type
        //hwr.Method = "GET";
        //HttpWebResponse hwb = (HttpWebResponse)hwr.GetResponse();

        //StreamReader sr = new StreamReader(hwb.GetResponseStream());
        //string resultats = sr.ReadToEnd();
        //sr.Close();

        //resultats = resultats.Replace("search?", "~/Search/Default.aspx?");

        //SearchResults = resultats;
        //this.Response.Redirect("~/Search/Default.aspx");

        this.Response.Redirect(ResolveUrl("~/Search/Default.aspx") + "?query=" + HttpUtility.UrlEncode(SearchText.Text.Trim()));
    }

    protected void SearchButton_Click(object sender, ImageClickEventArgs e)
    {
        Search();
    }

    #endregion

    #region class Heros
    public static class Heros
    {
        public enum HeroGrade
        {
            Elem,
            Middle,
            High,
        }
        public enum HeroIndex
        {
            A,
            B,
            C,
        }

        #region Static Fields

        public static readonly int MinIndexElem = 0;
        public static readonly int MaxIndexElem = MinIndexElem + 2;
        public static readonly int MinIndexMiddle = MaxIndexElem + 1;
        public static readonly int MaxIndexMiddle = MinIndexMiddle + 2;
        public static readonly int MinIndexHigh = MaxIndexMiddle + 1;
        public static readonly int MaxIndexHigh = MinIndexHigh + 2;

        public static readonly string[] HeroClasses = new string[]
      {
        "sub-hero-a-elem",   
        "sub-hero-b-elem",   
        "sub-hero-c-elem",
        "sub-hero-a-middle", 
        "sub-hero-b-middle", 
        "sub-hero-c-middle",
        "sub-hero-a-high",   
        "sub-hero-b-high",   
        "sub-hero-c-high"
      };

        private static Random _random;

        #endregion

        static Heros()
        {
            _random = new Random();
        }

        public static string GetRandomIndexHeroClass()
        {
            switch (_random.Next(3))
            {
                case 0:
                    return "index-hero-elem";
                case 1:
                    return "index-hero-middle";
                case 2:
                    return "index-hero-high";
                default:
                    return "index-hero-middle";
            }
        }

        public static string GetRandomHeroClass()
        {
            int index = _random.Next(HeroClasses.Length);
            return HeroClasses[index];
        }

        public static string GetRandomHeroClass(string lastClass)
        {
            string result = GetRandomHeroClass();
            while (result == lastClass)
                result = GetRandomHeroClass();
            return result;
        }

        public static string GetRandomHeroClass(HeroGrade grade)
        {


            switch (grade)
            {
                case HeroGrade.Elem:
                    return HeroClasses[MinIndexElem + _random.Next(3)];
                case HeroGrade.Middle:
                    return HeroClasses[MinIndexMiddle + _random.Next(3)];
                case HeroGrade.High:
                    return HeroClasses[MinIndexHigh + _random.Next(3)];
                default:
                    return HeroClasses[MinIndexMiddle + _random.Next(3)];
            }
        }

        public static string GetHeroClass(HeroGrade grade, HeroIndex index)
        {
            return HeroClasses[((int)grade * 3) + (int)index];
        }

        public static string GetHeroClass(int index)
        {
            if (index < 0 || index >= HeroClasses.Length)
                throw new ArgumentOutOfRangeException("index");
            return HeroClasses[index];
        }
    }
    #endregion

}

Open in new window

0
intlaqaCommented:
Hi,

Good, your code, yes, is big and I cannot try it here because I do not have all files and do not understand what project you are working on.

Anyway, I think the Page_Load is OK in the Masterpage, I just do not know why you place the following code in Page_Init:

AddTabLinks();
        SetRandomHero();
        BindStates();

        if (Request["st"] != null)
        {
            state.SelectedIndex = state.Items.IndexOf(state.Items.FindByText(Request["st"].ToString().ToUpper()));
        }

Could you please cut it and paste it in the Page_Load instead of Page_Init , to be :

protected void Page_Load(object sender, EventArgs e)
    {
if (!Page.IsPostBack)
        {
        AddTabLinks();
        SetRandomHero();
        BindStates();

        if (Request["st"] != null)
        {
         // remote this for now and try   state.SelectedIndex = state.Items.IndexOf(state.Items.FindByText(Request["st"].ToString().ToUpper()));
        }

     }

....
// Define the name, type and url of the client script on the page.

        String _swfObject = "SWFObjectScript";
        //String _mootools = "MooTools";
        String _utility = "Utility";
        String _utm = "UTM";
        String swfObjectUrl = ....
.....
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
-Dman100-Software ConsultantAuthor Commented:
Hi intlaga,

I tried moving the code from Page_Init into the Page_Load and wrapping it within if (!Page.IsPostBack), but the same problem still occurs.

I even commented out all the code form the Page_Load, Page_Init and the SelectedIndexChanged event handler in the master page.  Every event handler was commented out, so nothing should have interfered with the ItemCommand event on my page.

Any other ideas of what might be causing this to happen from the master page?

I am just grabbing at straws, trying to think of anything.
0
-Dman100-Software ConsultantAuthor Commented:
Hi intlaga,

It looks like I am going to have to re-build the master page bit by bit and test to determine what and where it breaks the code.

Thanks for all your help and the time and effort you put into debugging this issue with me.

Best Regards.
0
-Dman100-Software ConsultantAuthor Commented:
Problem is related to the master page.  The issue is currently unresovled.  The answersa nd code in this post are all correct.  Thanks again for the help.
0
intlaqaCommented:
You're welcome Dman, I am happy I helped you to find the problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.