我正在使用 ASP.Net C# 开发两个不同的站点。一个是网络项目,一个是网站。我在项目中有一个默认页面,它工作得很好,我想复制到网站上。项目默认在后面的代码中有一个命名空间。当我将代码复制到网站的默认值时,默认页面后面的代码没有命名空间,因此默认页面在网站中不起作用。我已经阅读了很多关于项目与站点以及命名空间与无命名空间的差异,但我找不到任何关于如何让默认值在网站中工作的信息。除了后面代码中的命名空间行之外,所有代码都是相同的。任何帮助将不胜感激。
enter code here
THE PAGE
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/DetailsOfRecipes.master"
AutoEventWireup="true" CodeFile="DetailsOfRecipes.aspx.cs" Inherits="DetailsOfRecipes" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<div id="masterLeftContainer">
<asp:Image ID="Image7" runat="server" CssClass="leftContainerImage" ImageUrl="~/Images/ketchup.png"
AlternateText="cabo view" />
</div>
<div class="masterLeftMenuContainer">
<div class="lowerLeftMenuContainer">
</div>
</div>
<div class="masterContentContainer">
<asp:Panel ID="pnl1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RecipeUploadConnectionString %>"
</asp:SqlDataSource>
<asp:ScriptManager ID="ScriptManager2" runat="server" />
<asp:ListView ID="ListView1" DataKeyNames="RecipeID" DataSourceID="SqlDataSource1"
runat="server">
<ItemTemplate>
<tr style="width: 500px">
<td rowspan="2">
<asp:Image ID="Image1" runat="server" Width="100px" Height="80px" ImageUrl='<%# "~/Handler.ashx?RecipeID=" + Eval("RecipeID")%>' />
</td>
<td rowspan="2" width="100px">
<asp:Rating ID="Rating1" runat="server" align="right" valign="top" CurrentRating='<%# Eval("RatingAVG")%>'
MaxRating="5" ReadOnly="true" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar"
FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar">
</asp:Rating>
   <br></br>
<asp:Label ID="Label7" runat="server" align="right" Text='<%# Eval("Count") %>' />  
<asp:Label ID="Label6" runat="server" Font-Size="12px" ForeColor="Blue" Text="Reviews"></asp:Label>
</td>
<td>
<asp:HyperLink ID="HyperLink2" runat="server" ForeColor="Blue" Width="275px" align="left"
NavigateUrl='<%# Bind("RecipeID", "~/RecipeDetails.aspx?RecipeId={0}") %>' Text='<%# Eval("RecipeName") %>'></asp:HyperLink>
</td>
<tr>
<td style="color: Purple">
<font color="red" size="2px">by:   </font>
<asp:Label ID="Name" runat="server" align="right" Text='<%# Eval("YourName") %>' />  
</td>
</tr>
</tr>
<tr style="width: 500px">
<td colspan="5" style="color: Navy">
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Description") %>' />
</td>
</tr>
<tr>
<td>
<br />
<br />
<font color="#OOOOFF" size="2px">INGREDIENTS</font>
</td>
</ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</asp:Panel>
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClick="btnPrint_Click" /><br />
<asp:Button ID="btnPrintCurrent" runat="server" Text="Print Current Page" OnClick = "PrintCurrentPage" />
</div>
<div class="masterRightMenuContainer">
</div>
<div class="masterRightMenuContainer">
<div class="lowerRightMenuContainer">
</div>
<div class="bottomRightMenuContainer">
</div>
</div>
</asp:Content>
THE CODE BEHIND
using System;
using System.Data;
using System.Data.SqlClient;
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;
using System.IO;
using System.Text;
using System.Web.SessionState;
public partial class DetailsOfRecipes : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
BindGrid();
}
private void BindGrid()
{
string strQuery = "select * " + "from PostedRecipes";
DataTable dt = new DataTable();
String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["RecipeUploadConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand(strQuery);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
//ListView1.DataSource = dt;
ListView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
sda.Dispose();
con.Dispose();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
/*Verifies that the control is rendered */
}
protected void OnPaging(object sender, PageEventArgs e)
{
ListView1.DataBind();
}
protected void PrintCurrentPage(object sender, EventArgs e)
{
ListView1.DataBind();
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
ListView1.RenderControl(hw);
string gridHTML = sw.ToString().Replace("\"", "'")
.Replace(System.Environment.NewLine, "");
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = new function(){");
sb.Append("var printWin = window.open('', '', 'left=0");
sb.Append(",top=0,width=1000,height=600,status=0');");
sb.Append("printWin.document.write(\"");
sb.Append(gridHTML);
sb.Append("\");");
sb.Append("printWin.document.close();");
sb.Append("printWin.focus();");
sb.Append("printWin.print();");
sb.Append("printWin.close();};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
ListView1.DataBind();
}