Click here to Skip to main content
14,696,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
Posted
Updated 16-Aug-10 13:22pm
v3
Comments
Sandeep Mewara 16-Aug-10 13:33pm
   
You don't need to post your emailid like this. It will just attract spam. Once someone replies you, automatically an email would be sent to your registered email-id with CodeProject.
Dalek Dave 16-Aug-10 18:23pm
   
Minor Edit for spelling.

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)?
   
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>



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
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"];
}
}
   
Comments
AspDotNetDev 16-Aug-10 18:32pm
   
This works fine for me in Visual Studio 2008 (I only pasted in the markup, as your code behind should not matter unless you've done something special to the inheritance hierarchy, which it appears you have not done). Perhaps you don't have a service pack installed? My installation says:

Microsoft Visual Studio 2008
Version 9.0.30729.1 SP

I'm pretty sure I had to download and install a service pack at some point or another.
Odd, 2008 is usually more stable than 2010.
   
v2
I have a version of Visual Studio 2008 Sp1 that is program VS90sp1-KB945140-ENU.exe.
I have already applied that patch.

Where are you seeing the version Version 9.0.30729.1 SP ?
   
Comments
AspDotNetDev 16-Aug-10 23:02pm
   
In the about dialog for Visual Studio.
Perhaps I should explain,,, the Application works fine, it's just that when I bring up the order.aspx in Design mode, there is just a blank screen. It does not display "Loading the Master Page", as it does in Visual Studio 2010. I can't see any visual representation of the order.aspx or the masterpage that it's inherited from.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900