2010-04-12 56 views
0

OK簡單的問題有關,包括我使用截至目前的#include大大多是靜態的html和asp.net代碼,我在想,如果I幀是處理一個更好的辦法我想做什麼或者有更好的方法來做到這一點。這裏是目前的方法,我處理包括的#include文件VS iframe或是否有更好的辦法

的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"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <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">Help</a></td> 
           </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">Help</a> 
         </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'"> 
        <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"> 
         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"> 
         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'"><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'"> 
           <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'"><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'"><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'"><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> 

重新編制我的例子試圖使這成爲一個統一通信,但我遇到了服務器腳本的問題,它不允許我混淆它更多。

回答

4

沒有理由在這種情況下使用iframe的。其缺點是:

  • 它們的大小是固定
  • 他們不記入你的SEO頁面
  • ,則無法訪問的項目的DOM在他們(做腳本)

所以我會「包括」文件。使用ASP.NET,您最好的選擇是User ControlsMaster Pages

+0

但是我使用的應用程序應該使用母版頁或用戶控件。隨着包含的想法,這隻會是一個大型網站上的子目錄。 – 2010-04-12 14:59:35

+0

母版頁是一個「佈局」容器。您可以使用它將頁眉,頁腳,導航和內容放入正確的格式。您的網站上可以有許多母版頁。用戶控件應該是特定的組件,即顯示客戶的方式。希望這可以幫助。 – Fenton 2010-04-12 15:15:31

+0

這不一定是針對整個網站的,您可以使用這個實例的用戶控件。 – Keltex 2010-04-12 15:16:10

1

使用iframe將導致客戶端瀏覽器,以使另一個HTTP請求,以便檢索其內容。除非你有真正的特定需求(比如將代碼粘貼到其他人的網站),否則你可能永遠都不想使用iframe。

我實在不明白I幀的地步,但我接受建議。如果你需要動態內容,你可以使用AJAX和普通的div。如果您的服務器出於某種原因需要包含來自其他域或服務器的內容,則可以使用curl。

相關問題