关于包含大部分静态html和asp.net代码的简单问题我现在正在使用#include,我想知道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">
</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>
重做我试图将其变成UC的示例但是我遇到了服务器脚本的问题,它不允许我对它进行更多的混淆。
答案 0 :(得分:4)
在这种情况下没有理由使用IFRAME。他们的缺点是:
所以我会“包含”一个文件。使用ASP.NET,最好的选择是User Controls或Master Pages。
答案 1 :(得分:1)
使用iframe将导致客户端浏览器发出另一个HTTP请求以检索其内容。除非你有特别需要(比如将代码粘贴到别人的网站上),否则你可能永远不想使用iframe。
我真的没有看到iframe的观点,但我愿意接受建议。如果您需要动态内容,可以使用AJAX和普通div。如果您的服务器由于某种原因需要包含来自其他域或服务器的内容,则可以使用curl。