views:

196

answers:

2

ok simple question about including large mostly static html and asp.net code I am using as of right now #include and I was wondering if iframes would be a better way of handling what I wish to do or is there a better way to do it. here is the current way i'm handling the includes

default.aspx

    <%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" %>

    <%@ Import Namespace="YAF.Classes.Core" %>


<script runat="server">

    protected void Page_Load(object sender, System.EventArgs e)
    {

        btnSearch.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(btnSearch, "") + ";this.disabled = true;"); 
        if (forum.PageUserID != 1)
        {
            Page.FindControl("divGuest").Visible = false;
            Page.FindControl("divUser").Visible = true;
            lblUserName.Text = forum.PageUserName;
        }
        else
        {
            Page.FindControl("divGuest").Visible = true;
            Page.FindControl("divUser").Visible = false;
            lblUserName.Text = null;
        }

    }
    public void Page_Error(object sender, System.EventArgs e)
    {
        Exception x = Server.GetLastError();
        YAF.Classes.Data.DB.eventlog_create(YafServices.InitializeDb.Initialized ? (int?)YafContext.Current.PageUserID : null, this, x);
        YAF.Classes.Core.CreateMail.CreateLogEmail(x);
    }


    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (txtSearch.Text.Length > 4)
        {
            if(ddlCriteria.SelectedValue == "Posts")
                Response.Redirect("default.aspx?g=search&search=" + txtSearch.Text);
            if(ddlCriteria.SelectedValue == "Posted By")
                Response.Redirect("default.aspx?g=search&postedby=" + txtSearch.Text);
        }

    }
</script>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <head id="YafHead" runat="server">
    <meta id="YafMetaDescription" runat="server" name="description" content="Yet Another Forum.NET -- A bulletin board system written in ASP.NET" />
    <meta id="YafMetaKeywords" runat="server" name="keywords" content="Yet Another Forum.net, Forum, ASP.NET, BB, Bulletin Board, opensource" />
    <title>Forums</title>
    <style type="text/css">
     .sbutton 
     {
    background-color:#361800;
    border:medium none;
    border-collapse:collapse;
    color:#FFFFFF;
    font-family:Tahoma,Arial,Helvetica;
    font-size:10px;
    font-weight:bold;
    vertical-align:middle;
    }
   </style> 
   <link href="images/favicon.ico" type="image/ico" rel="shortcut icon" /> 
    <link rel="stylesheet" href="navTopStyle.css" type="text/css" media="screen" />
    </head>
    <body style="margin: 0">
    <form id="form1" runat="server" enctype="multipart/form-data">
    <table align="center" style="background-color: #ffffff" cellpadding="0" cellspacing="0"
        width="790px">
        <tr>
            <td>
                <!--#include file="CComHeader.html"-->
            </td>
        </tr>
        <tr>
            <td>
                <YAF:Forum runat="server" ID="forum"></YAF:Forum>
            </td>
        </tr>
    </table>
    </form>
    </body>
    </html>

CComHeader.html

<table cellpadding="0" cellspacing="0" width="790px">
    <tr>
        <td align="left">
            <img src="images/smokechair.jpg" alt="Cigar.com" /><img src="images/cigarcomTitle.gif"
                alt="Cigar.com" />
        </td>
        <td align="right">
            <table width="310px" height="73px" cellpadding="0" cellspacing="0" style="padding-right: 6px">
                <tr>
                    <td width="109px" class="welcome" align="left">
                    Welcome to Cigar.com
                    </td>
                    <td width="195px" class="welcome" align="left">
                        <div runat="server" id="divUser">
                            <table cellpadding="0" cellspacing="0" align="right">
                                <tr>
                                    <td width="126px" align="left">
                                        <asp:Label ID="lblUserName" CssClass="welcome" runat="server"></asp:Label></td>
                                    <td width="65px" align="left">
                                        <a href="http://www.cigar.com/cs/languages/en-US/docs/faq.aspx"&gt;Help&lt;/a&gt;&lt;/td&gt;
                                </tr>
                            </table>
                        </div>
                        <div runat="server" id="divGuest">
                            <a href="OutsideLogin.aspx">Sign In</a> | <a href="OutsideLogin.aspx">Join</a> |
                            <a href="http://www.cigar.com/cs/languages/en-US/docs/faq.aspx"&gt;Help&lt;/a&gt;
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <table cellpadding="0" cellspacing="0" >
                            <tr>
                                <td width="234px" align="right">
                                    <asp:DropDownList ID="ddlCriteria" runat="server">
                                        <asp:ListItem>Posts</asp:ListItem>

                                        <asp:ListItem>Posted By</asp:ListItem>
                                    </asp:DropDownList>
                                <asp:TextBox Width="120px" ID="txtSearch" runat="server"></asp:TextBox>
                                </td>
                                <td width="70px" align="center">
                                            <asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="sbutton" OnClick="btnSearch_Click" />

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td colspan="2">
        <!--#include file="commonTabBar.html" -->

        </td>
    </tr>
</table>

commonTabBar.html

<div class="CommonTabBar">

    <script language="javascript">
        function tabOver(e) {
            if (e.className != 'CommonSimpleTabStripSelectedTab')
                e.className = 'CommonSimpleTabStripTabHover';
        }
        function tabOut(e) {
            if (e.className != 'CommonSimpleTabStripSelectedTab')
                e.className = 'CommonSimpleTabStripTab';
        }
        function tabOverSub(e) {
            if (e.className != 'CommonSimpleTabStripSelectedTabSub')
                e.className = 'CommonSimpleTabStripTabHoverSub';
        }
        function tabOutSub(e) {
            if (e.className != 'CommonSimpleTabStripSelectedTabSub')
                e.className = 'CommonSimpleTabStripTabSub';
        }
    </script>

    <table border="0" cellpadding="0" cellspacing="0">
        <tbody>
            <tr valign="middle">
                <td class="CommonSimpleTabStripTab" style="padding: 0px">
                    &nbsp;
                </td>
                <td class="CommonSimpleTabStripTab" onmouseover="tabOver(this);" onmouseout="tabOut(this);"
                    onclick="window.location = 'http://www.cigar.com/index.asp'"&gt;
                    <a style="float: right; display: block; height: 30px; line-height: 30px; padding-left: 12px;
                        padding-right: 12px; vertical-align: middle;" href="http://www.cigar.com/index.asp"&gt;
                        Home</a>
                </td>
                <td class="CommonSimpleTabStripTab" onmouseover="tabOver(this); document.getElementById('ComDropDown2').style.display = 'inline';"
                    onmouseout="tabOut(this); document.getElementById('ComDropDown2').style.display = 'none';">
                    <a style="float: right; display: block; height: 30px; line-height: 30px; padding-left: 12px;
                        padding-right: 12px; vertical-align: middle;" href="http://www.cigar.com/cigars/index.asp"&gt;
                        Cigars</a>
                    <div id="ComDropDown2" style="border: 1px solid rgb(71, 42, 24); margin: 28px 0px 0px;
                        display: none; background-color: rgb(235, 230, 208); color: rgb(71, 42, 24);
                        position: absolute; float: left; z-index: 200;" onmouseover="document.getElementById('ComDropDown2').style.display = 'inline';"
                        onmouseout="document.getElementById('ComDropDown2').style.display = 'none';">
                        <ul style="margin: 0px; padding: 0px; width: 100px;">
                            <li class="CommonSimpleTabStripTabSub" style="margin: 0px; padding: 3px; text-align: left;
                                list-style: none outside none;" onmouseover="tabOverSub(this); " onmouseout="tabOutSub(this); "
                                onclick="window.location = 'http://www.cigar.com/cigars/index.asp'"&gt;&lt;a href="http://www.cigar.com/cigars/index.asp"
                                    style="line-height: 25px; color: rgb(71, 42, 24);" id="BrandsLink">Brands </a>
                            </li>
                            <li class="CommonSimpleTabStripTabSub" style="margin: 0px; padding: 3px; text-align: left;
                                list-style: none outside none;" onmouseover="tabOverSub(this); " onmouseout="tabOutSub(this); "
                                onclick="window.location = 'http://www.cigar.com/cigars/privatelabel.asp?brand=419'"&gt;
                                <a href="http://www.cigar.com/cigars/privatelabel.asp?brand=419" style="line-height: 25px;
                                    color: rgb(71, 42, 24);" id="SamplersLink">Aging Room </a></li>
                            <li class="CommonSimpleTabStripTabSub" style="margin: 0px; padding: 3px; text-align: left;
                                list-style: none outside none;" onmouseover="tabOverSub(this); " onmouseout="tabOutSub(this); "
                                onclick="window.location = 'http://www.cigar.com/cigars/samplers.asp'"&gt;&lt;a href="http://www.cigar.com/cigars/samplers.asp"
                                    style="line-height: 25px; color: rgb(71, 42, 24);" id="SamplersLink">Samplers
                                </a></li>
                            <li class="CommonSimpleTabStripTabSub" style="margin: 0px; padding: 3px; text-align: left;
                                list-style: none outside none;" onmouseover="tabOverSub(this); " onmouseout="tabOutSub(this); "
                                onclick="window.location = 'http://www.cigar.com/cigars/suggestions.asp'"&gt;&lt;a href="http://www.cigar.com/cigars/suggestions.asp"
                                    style="line-height: 25px; color: rgb(71, 42, 24);" id="SuggestionsLink">Suggestions
                                </a></li>
                            <li class="CommonSimpleTabStripTabSub" style="margin: 0px; padding: 3px; text-align: left;
                                list-style: none outside none;" onmouseover="tabOverSub(this); " onmouseout="tabOutSub(this); "
                                onclick="window.location = 'http://www.cigar.com/DailyDeal/ccCigarDeals.asp'"&gt;&lt;a
                                    href="http://www.cigar.com/DailyDeal/ccCigarDeals.asp" style="line-height: 25px;
                                    color: rgb(71, 42, 24);" id="SuggestionsLink">Suggestions </a></li>
                        </ul>
                    </div>

Redid the example I was trying to make this into a UC but I ran into a problem with the server script and it not allowing me to obfuscate it more.

+4  A: 

There's no reason to use IFRAMEs in this scenario. Their disadvantages are:

  • They are fixed in size
  • They don't count for the SEO on your page
  • You can't access the DOM for items in them (to do scripting)

So I would "include" a file. With ASP.NET your best bet is User Controls or Master Pages.

Keltex
but for the application i am using should I use a master page or user control. With the included idea that this will only be a sub directory on a larger site.
Laurence Burke
A master page is a "layout" container. You can use it to put header, footer, navigation and content into the right format. You can have many master pages on your website. A user control should be a specific component, i.e. a way to display a customer. Hope this helps.
Sohnee
This doesn't have to be for the whole site, you can use a user control for this one instance.
Keltex
Changed the code shown was trying to put it into a UC now im having a problem with the obfuscation of the control forum.
Laurence Burke
@Laurence - Put the Page_Load in your .ascx file because that's where those controls reside.
Keltex
+1  A: 

Using an iframe will cause the client browser to make another HTTP request in order to retrieve its contents. Unless you have a really specific need (like sticking your code into someone else's website) you probably never want to use an iframe.

I don't really see the point of iframes, but I'm open to suggestion. If you need dynamic content, you can use AJAX and normal divs. If your server for some reason needs to include content from another domain or server, you can use curl.

Fletcher Moore