Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : 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
 
Old December 7th, 2011, 08:19 AM
Authorized User
 
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
Default CH 17 Storing Genre Preferences in the Profile - Error!

CH 17 Storing Genre Preferences in the Profile

Completed this and ran it. However, I get a build error as below:


Code:
Error	1	The type or namespace name 'Collection' does not exist in the namespace 'System' (are you missing an assembly reference?)	c:\Users\Admin\AppData\Local\Temp\Temporary ASP.NET Files\clientmanagertest\9bf60365\afcf33db\App_Code.cessscad.1.cs
Here is my code behind: (I am using FavoriteIssues instead of FavoriteGenres)

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserProfile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            FirstName.Text = Profile.FirstName;
            LastName.Text = Profile.LastName;
            DateOfBirth.Text = Profile.DateOfBirth.ToShortDateString();
            Bio.Text = Profile.Bio;
        }
    }
    protected void SaveButton_Click(object sender, EventArgs e)
    {
if (Page.IsValid)
        {
            Profile.FirstName = FirstName.Text;
            Profile.LastName = LastName.Text;
            Profile.DateOfBirth = DateTime.Parse(DateOfBirth.Text);
            Profile.Bio = Bio.Text;
    //Clear the existing list
    Profile.FavoriteIssues.clear();

    //Now add the selected Issues
   foreach (ListItem myItem in PreferenceList.Items)
    {
        if (myItem.Selected)
    {
            Profile.FavoriteIssues.Add(Convert.ToInt32(myItem.Value));
        }
        }
    }
        protected void PreferenceList_DataBound(object sender, EventArgs e)
    {
        foreach (ListItem myitem in PreferenceList.Items)
        {
            int currentValue = Convert.ToInt32(myitem.Value);
            if (Profile.FavoriteIssues.contains(currentValue))
            {
                myitem.Selected = true;
            }
    }
}
And Web Config:

Code:
 <profile>
      <properties>
        <add name="FirstName" />
        <add name="LastName" />
        <add name="DateOfBirth" type="System.DateTime" />
        <add name="Bio" />
        <add name="FavoriteIssues" type="System.Collection.Generic.List`1[System.Int32]" />
      </properties>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>
 
Old December 7th, 2011, 08:29 AM
Authorized User
 
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Ahhh - Found it. I had misspelt collections as collection!

Now the next issue on the same page.


Quote:
Error 1 'System.Collections.Generic.List<int>' does not contain a definition for 'clear' and no extension method 'clear' accepting a first argument of type 'System.Collections.Generic.List<int>' could be found (are you missing a using directive or an assembly reference?) C:\BegASPNET\clientManagerTest\UserProfile.aspx.cs 29 36 C:\BegASPNET\clientManagerTest\


Error 2 'System.Collections.Generic.List<int>' does not contain a definition for 'contains' and no extension method 'contains' accepting a first argument of type 'System.Collections.Generic.List<int>' could be found (are you missing a using directive or an assembly reference?) C:\BegASPNET\clientManagerTest\UserProfile.aspx.cs 47 40 C:\BegASPNET\clientManagerTest\
 
Old December 7th, 2011, 08:34 AM
Authorized User
 
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Doh!

I re-typed the two lines in the code behind and the error disappeared. Even though it said exactly the same as before!

Why does that happen?
 
Old December 7th, 2011, 01:20 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Why does that happen?
Judging from the earlier, code, it seems you used clear with a lower case c. Since C# is case sensitive, and the method is called Clear with a capital C, you get an error.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
leeWozyWarren (December 7th, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 17 Creating a Profile... error! leeWozyWarren BOOK: Beginning ASP.NET 4 : in C# and VB 3 December 6th, 2011 06:25 PM
Ch 17 Storing Basic User Data in the Profile - dateOfBirth Error! leeWozyWarren BOOK: Beginning ASP.NET 4 : in C# and VB 1 December 6th, 2011 06:22 PM
CH 17 - Assemblies equintana71 BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 1 May 17th, 2011 09:20 PM
error in ch 17 on running both fils no17 Beginning PHP 0 May 10th, 2008 02:15 AM
IStateManager.TrackViewState() Ch 17 EdKroket BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 0 January 25th, 2007 07:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.