 |
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

June 4th, 2014, 12:31 AM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 14 error
Hi;
I get an error when running the example from p530, and am hoping there is an easy solution. Everything to this point has run with no problems.
I rewrote the ListView, renaming it ListView2, and then the error was for ListView2
This is the error:
An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server".
My aspx code is:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" ItemType="Picture" SelectMethod="ListView1_GetData" >
<EmptyDataTemplate>
No pictures found for this photo album
</EmptyDataTemplate>
<ItemTemplate>
<li>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Item.ImageUrl %>' ToolTip='<%# Item.ToolTip %>' />
<asp:Label ID="Description" runat="server" Text='<%# Item.Description %>' />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li id="itemPlacholder" runat="server" />
</ul>
<div style="clear: both;">
<asp:DataPager ID="DataPager1" runat="server" PageSize="3">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="true" ShowLastPageButton="true" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
</asp:ListView>
Do you see any error, or is there anything else I can try to isolate the problem? I am new to ASP.NET so anything could be overlooked.
Thanks in advance
Barrie
|
|

June 4th, 2014, 03:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
I don't see an obvious error with this code, but also don't see ListView2 so maybe this isn't the correct code?
Can you post the full markup and code behind for the page and the exact error message? Then I can take another look.
Cheers,
Imar
|
|

June 4th, 2014, 08:30 AM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry I confused you with the reference to ListView2. I programed it as below. When I had the error I changed the name from ListView1 to ListView2 and changed back when that also errored. Today I deleted the "Default.aspx" in the PhotoAlbums folder and re-typed. I still get the same error. To execute I have open just the Default.aspx page and press Ctrl+F5, the execute window pops up with the error message.
Error
Server Error in '/' Application.
An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server".
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server".]
System.Web.UI.WebControls.ListView.GetPreparedCont ainerInfo(Control outerContainer, Boolean isItem, Int32& placeholderIndex) +503
System.Web.UI.WebControls.ListView.CreateItemsWith outGroups(ListViewPagedDataSource dataSource, Boolean dataBinding, InsertItemPosition insertPosition, ArrayList keyArray) +64
System.Web.UI.WebControls.ListView.CreateChildCont rols(IEnumerable dataSource, Boolean dataBinding) +1035
System.Web.UI.WebControls.ListView.PerformDataBind ing(IEnumerable data) +35
System.Web.UI.WebControls.DataBoundControl.OnDataS ourceViewSelectCallback(IEnumerable data) +123
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +33
System.Web.UI.WebControls.DataBoundControl.Perform Select() +138
System.Web.UI.WebControls.ListView.PerformSelect() +102
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +30
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +105
System.Web.UI.WebControls.ListView.CreateChildCont rols() +52
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446
Here is the full markup:
<%@ Page Title="All Photo Albums" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="PhotoAlbums_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="PhotoAlbumList" runat="server" AutoPostBack="True"
DataTextField="Name" DataValueField="Id"
OnSelectedIndexChanged="PhotoAlbumList_SelectedInd exChanged" SelectMethod="PhotoAlbumList_GetData">
</asp:DropDownList>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id"
ItemType="Picture" SelectMethod="ListView1_GetData" >
<EmptyDataTemplate>
No pictures found for this photo album
</EmptyDataTemplate>
<ItemTemplate>
<li>
<asp:Image ID="Image1" runat="server"
ImageUrl='<%# Item.ImageUrl %>' ToolTip='<%# Item.ToolTip %>' />
<asp:Label ID="Description" runat="server" Text='<%# Item.Description %>' />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li id="itemPlacholder" runat="server" />
</ul>
<div style="clear: both;">
<asp:DataPager ID="DataPager1" runat="server" PageSize="3">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button"
ShowFirstPageButton="true" ShowLastPageButton="true" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Here is the code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class PhotoAlbums_Default : BasePage
{
PlanetWroxEntities entities = new PlanetWroxEntities();
public IEnumerable<PhotoAlbum> PhotoAlbumList_GetData()
{
return from p in entities.PhotoAlbums
orderby p.Id
select p;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PhotoAlbumList_SelectedIndexChanged(object sender, EventArgs e)
{
ListView1.DataBind();
}
// The return type can be changed to IEnumerable, however to support
// paging and sorting, the following parameters must be added:
// int maximumRows
// int startRowIndex
// out int totalRowCount
// string sortByExpression
public IQueryable<Picture> ListView1_GetData()
{
int photoAlbumId = Convert.ToInt32(PhotoAlbumList.SelectedValue);
return from p in entities.Pictures
where p.PhotoAlbumId == photoAlbumId
orderby p.Id
select p;
}
}
Thank you for taking the time to review. I believe I followed your instructions, but if I missed something please point it out.
Most appreciated
Barrie
|
|

June 4th, 2014, 10:07 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Barrie,
I think the error message is spot on. Take a look at this:
Code:
<li id="itemPlacholder" runat="server" />
You're missing an e in Placeholder....
Imar
|
|

June 4th, 2014, 02:26 PM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
Error in Code?
This is kind of surprising because Imar's code usually runs really good right out of the box. I have never had any issues with it. I just wish I could say the same thing about some of the other ASP.NET code downloads that I have tried to run after downloading. Talk about getting compile errors they come in gobs and gobs.
|
|

June 4th, 2014, 11:01 PM
|
|
Registered User
|
|
Join Date: Apr 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar; Thank you so much.
vbboyd: The mistake was mine, it was not in the code Imar provided. I like to type the examples as part of my learning, and this was a good lesson in checking my typing more carefully. The error message did tell me, but I overlooked the obvious. Another pair of eyes was the solution.
|
|

June 5th, 2014, 12:04 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
|
|
Item placeholder
id="itemPlacholder"
"itemPlaceholder" is a unique id in the DOM? That confuses me. It should be by way of HTML. Is "itemPlaceholder" a unique Id or the reserved name of an actual asp.net server control straight from Visual Studio Toolbox? I just don't remember now. I have been doing way too much MVC, WCF and Web Api with JQuery Mobile lately to remember any of that stuff anymore. I need a refresher on ASP.NET web form stuff the basic stuff like this again to jog my memory back into shape. That is probably a good reason why I need to go through this book after doing the two other previous editions of this book. Of course I shouldn't ask a stupid question like that, Imar will just chide me relentlessly for asking it.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Chapter 14 - All.aspx error |
Dbug |
BOOK: Beginning ASP.NET 4.5 : in C# and VB |
6 |
September 18th, 2013 09:13 AM |
| Chapter 14 - Error inserting |
usmaak |
BOOK: Beginning ASP.NET 4.5 : in C# and VB |
12 |
March 10th, 2013 11:15 PM |
| Chapter 14 Code Error? |
pherank |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 |
1 |
July 4th, 2008 09:05 PM |
|
 |
|