母版页,内容页显示 [英] Master Page, Content Page display

查看:81
本文介绍了母版页,内容页显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2008,但是我尝试构建的内容"页面的显示出现问题.

当我在设计"选项卡中显示内容页面时,未加载母版页.我只得到一个空白页.

在Visual Studio 2010中,我没有问题.
任何建议将不胜感激.

谢谢
唐·迪斯顿
[删除电子邮件ID以避免显示]

I am working with Visual Studio 2008, and I am having a problem with the display of the Content page that I''m trying to build.

When I display the content page in the Design tab, the master page is not loaded. I just get a blank page.

In visual studio 2010, I don''t have the problem.
Any suggestion would be greatly appreciated.

Thank You
Don Diston
[Email id removed to avoid display]

推荐答案

在2008年对我来说效果很好.正如我的编程老师曾经说过的,您拼写错误".也许您可以在(母版)页面上发布标记,以便我们尝试一下?

另外,您是否正在使用ASP.Net Web应用程序或ASP.Net网站(在Visual Studio中有所不同)?
Works fine for me in 2008. As my programming teacher used to say, "you spelled it wrong". Perhaps you could post the markup for your (master)pages so we can give it a try?

Also, are you working with an ASP.Net Web Application or an ASP.Net Website (there''s a difference in Visual Studio)?


就像我之前说的那样,这可以正常工作在Visual Studio 2010中.
我正在使用Visual Studio Web应用程序.

母版页:

As I said before,,, this works fine in Visual Studio 2010.
I am using Visual Studio Web Application.

Master Page:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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>Chapter 9: Master Page</title>
    <style type="text/css">
        .Row1Column1
        {
            width: 160px;
            height: 400px;
            border-color: Red;
            background-color: Red;
        }
        .Row1Column2
        {
            width: 10px;
            height: 400px;
        }
        .Row1Column3
        {
            width: 520px;
            height: 400px;
        }
        .Row2Column1
        {
            width: 160px;
            height: 25px;
            border-color: Red;
            background-color: Red;
        }
        .Row2Column2
        {
            width: 10;
            height: 25;
        }
        .Row2Column3
        {
            width: 520px;
            height: 25;
        }
    </style>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/banner.jpg" />
        <br />
        <table cellpadding="2" cellspacing="0">
            <tr>
                <td class="Row1Column1" valign="top">
                    <br />
                    <asp:HyperLink ID="HyperLink1" runat="server"

                        ForeColor="White"

                        NavigateUrl="~/Order.aspx">Home</asp:HyperLink>
                    <br />
                    <br />
                    <asp:HyperLink ID="HyperLink2" runat="server"

                        ForeColor="White" NavigateUrl="~/Cart.aspx">
                        Your Shopping Cart</asp:HyperLink>
                    <br />
                    <br />
                    <asp:HyperLink ID="HyperLink3" runat="server"

                        ForeColor="White" NavigateUrl="~/Service.aspx">
                        Customer Service</asp:HyperLink>
                    <br />
                    <br />
                    <asp:HyperLink ID="HyperLink4" runat="server"

                        ForeColor="White"

                        NavigateUrl="~/About.aspx">About Us</asp:HyperLink>
                </td>
                <td class="Row1Column2"></td>
                <td class="Row1Column3" valign="top">
                   <asp:ContentPlaceHolder id="Main" runat="server"></asp:ContentPlaceHolder>
                </td>
            </tr>
            <tr>
                <td class="Row2Column1"></td>
                <td class="Row2Column2"></td>
                <td class="Row2Column3">
                    <asp:Label ID="lblMessage" runat="server"></asp:Label>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>




背后的代码:

使用系统;
使用System.Collections;
使用System.Configuration;
使用System.Data;
使用System.Linq;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Xml.Linq;
公共局部类MasterPage:System.Web.UI.MasterPage
{
受保护的void Page_Load(对象发送者,EventArgs e)
{
int daysUntil = DaysUntilHalloween();
如果(daysUntil == 0)
lblMessage.Text =万圣节快乐!";
否则,如果(daysUntil == 1)
lblMessage.Text =明天是万圣节!";
其他
lblMessage.Text =只有" + daysUntil
+距万圣节还有几天!";
}
private int DaysUntilHalloween()
{
DateTime万圣节=新的DateTime(DateTime.Today.Year,10,31);
如果(DateTime.Today>万圣节)
万圣节=万圣节.AddYears(1);
TimeSpan ts =万圣节-DateTime.Today;
返回ts.Days;
}
}


ORDER.ASPX




Code Behind:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
int daysUntil = DaysUntilHalloween();
if (daysUntil == 0)
lblMessage.Text = "Happy Halloween!";
else if (daysUntil == 1)
lblMessage.Text = "Tomorrow is Halloween!";
else
lblMessage.Text = "There are only " + daysUntil
+ " days left until Halloween!";
}
private int DaysUntilHalloween()
{
DateTime halloween = new DateTime(DateTime.Today.Year, 10, 31);
if (DateTime.Today > halloween)
halloween = halloween.AddYears(1);
TimeSpan ts = halloween - DateTime.Today;
return ts.Days;
}
}


ORDER.ASPX

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Order.aspx.cs" Inherits="Order" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .style1
        {
            width: 250px;
        }
        .style2
        {
            width: 20px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main" Runat="Server">
    <br />
    <asp:Label ID="Label1" runat="server"

        Text="Please select a product:"></asp:Label>&nbsp;
    <asp:DropDownList ID="ddlProducts" runat="server"

        DataSourceID="AccessDataSource1" DataTextField="Name"

        DataValueField="ProductID" Width="150px" AutoPostBack="True">
    </asp:DropDownList>
    <asp:AccessDataSource ID="AccessDataSource1" runat="server"

        DataFile="~/App_Data/Halloween.mdb"

        SelectCommand="SELECT [ProductID], [Name], [ShortDescription],
            [LongDescription], [ImageFile], [UnitPrice]
            FROM [Products] ORDER BY [Name]">
    </asp:AccessDataSource>
    <br />
    <table>
        <tr>
            <td class="style1">
                <asp:Label ID="lblName" runat="server"

                    style="font-weight: 700; font-size: larger">
                </asp:Label>
            </td>
            <td class="style2" rowspan="4">
            </td>
            <td rowspan="4" valign="top">
                <asp:Image ID="imgProduct" runat="server" Height="200px" />
            </td>
        </tr>
        <tr>
            <td class="style1">
                <asp:Label ID="lblShortDescription" runat="server">
                </asp:Label>
            </td>
        </tr>
        <tr>
            <td class="style1">
                <asp:Label ID="lblLongDescription" runat="server">
                </asp:Label>
            </td>
        </tr>
        <tr>
            <td class="style1">
                <asp:Label ID="lblUnitPrice" runat="server"

                    style="font-weight: 700; font-size: larger">
                </asp:Label>
                <asp:Label ID="Label2" runat="server" Text="each"

                    style="font-weight: 700; font-size: larger">
                </asp:Label>
            </td>
        </tr>
    </table>
    <br />
    <asp:Label ID="Label3" runat="server" Text="Quantity:"

        Width="80px"></asp:Label>
    <asp:TextBox ID="txtQuantity" runat="server" Width="80px">
    </asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1"

        runat="server" ControlToValidate="txtQuantity" Display="Dynamic"

        ErrorMessage="Quantity is a required field.">
    </asp:RequiredFieldValidator>
    <asp:RangeValidator ID="RangeValidator1" runat="server"

        ControlToValidate="txtQuantity" Display="Dynamic"

        ErrorMessage="Quantity must range from 1 to 500."

        MaximumValue="500" MinimumValue="1" Type="Integer">
    </asp:RangeValidator><br /><br />
    <asp:Button ID="btnAdd" runat="server" Text="Add to Cart"

        OnClick="btnAdd_Click" />&nbsp;
    <asp:Button ID="btnCart" runat="server" CausesValidation="False"

        PostBackUrl="~/Cart.aspx" Text="Go to Cart" />
</asp:Content>




CODE BEHIND
使用系统;
使用System.Collections;
使用System.Configuration;
使用System.Data;
使用System.Linq;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Xml.Linq;
public partial class Order : System.Web.UI.Page
{
private Product selectedProduct;
受保护的void Page_Load(对象发送者,EventArgs e)
{
如果(!IsPostBack)
ddlProducts.DataBind();
selectedProduct = this.GetSelectedProduct();
lblName.Text = selectedProduct.Name;
lblShortDescription.Text = selectedProduct.ShortDescription;
lblLongDescription.Text = selectedProduct.LongDescription;
lblUnitPrice.Text = selectedProduct.UnitPrice.ToString("c");
imgProduct.ImageUrl = "Images/Products/" + selectedProduct.ImageFile;
}
private Product GetSelectedProduct()
{
DataView productsTable = (DataView)
AccessDataSource1.Select(DataSourceSelectArguments.Empty);
productsTable.RowFilter =
"ProductID = ''" + ddlProducts.SelectedValue + "''";
DataRowView row = (DataRowView) productsTable[0];
Product p = new Product();
p.ProductID = row["ProductID"].ToString();
p.Name = row["Name"].ToString();
p.ShortDescription = row["ShortDescription"].ToString();
p.LongDescription = row["LongDescription"].ToString();
p.UnitPrice = (decimal) row["UnitPrice"];
p.ImageFile = row["ImageFile"].ToString();
return p;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
CartItem item = new CartItem();
item.Product = selectedProduct;
item.Quantity = Convert.ToInt32(txtQuantity.Text);
this.AddToCart(item);
Response.Redirect("Cart.aspx");
}
}
private void AddToCart(CartItem item)
{
SortedList cart = this.GetCart();
string productID = selectedProduct.ProductID;
if (cart.ContainsKey(productID))
{
CartItem existingItem = (CartItem) cart[productID];
existingItem.Quantity += item.Quantity;
}
其他
cart.Add(productID, item);
}
private SortedList GetCart()
{
if (Session["Cart"] == null)
Session.Add("Cart", new SortedList());
return (SortedList) Session["Cart"];
}
}




CODE BEHIND
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Order : System.Web.UI.Page
{
private Product selectedProduct;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
ddlProducts.DataBind();
selectedProduct = this.GetSelectedProduct();
lblName.Text = selectedProduct.Name;
lblShortDescription.Text = selectedProduct.ShortDescription;
lblLongDescription.Text = selectedProduct.LongDescription;
lblUnitPrice.Text = selectedProduct.UnitPrice.ToString("c");
imgProduct.ImageUrl = "Images/Products/" + selectedProduct.ImageFile;
}
private Product GetSelectedProduct()
{
DataView productsTable = (DataView)
AccessDataSource1.Select(DataSourceSelectArguments.Empty);
productsTable.RowFilter =
"ProductID = ''" + ddlProducts.SelectedValue + "''";
DataRowView row = (DataRowView) productsTable[0];
Product p = new Product();
p.ProductID = row["ProductID"].ToString();
p.Name = row["Name"].ToString();
p.ShortDescription = row["ShortDescription"].ToString();
p.LongDescription = row["LongDescription"].ToString();
p.UnitPrice = (decimal) row["UnitPrice"];
p.ImageFile = row["ImageFile"].ToString();
return p;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
CartItem item = new CartItem();
item.Product = selectedProduct;
item.Quantity = Convert.ToInt32(txtQuantity.Text);
this.AddToCart(item);
Response.Redirect("Cart.aspx");
}
}
private void AddToCart(CartItem item)
{
SortedList cart = this.GetCart();
string productID = selectedProduct.ProductID;
if (cart.ContainsKey(productID))
{
CartItem existingItem = (CartItem) cart[productID];
existingItem.Quantity += item.Quantity;
}
else
cart.Add(productID, item);
}
private SortedList GetCart()
{
if (Session["Cart"] == null)
Session.Add("Cart", new SortedList());
return (SortedList) Session["Cart"];
}
}


Odd, 2008 is usually more stable than 2010.
Odd, 2008 is usually more stable than 2010.


这篇关于母版页,内容页显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆