Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 26th, 2011, 04:05 PM
Authorized User
Points: 157, Level: 3
Points: 157, Level: 3 Points: 157, Level: 3 Points: 157, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default TIO page 552: Exception when trying to run Default.aspx in browser

Hi Imar,

Apparently, something is wrong with my Default.aspx, from the PhotoAlbums folder. Checking it against your source code, I could not find a discrepancy.

Would u pls suggest a way to debug this problem or where it might be?

Thanks for your help. mk

Here is the exception from the browser:
Code:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Operator '==' incompatible with operand types 'Int32' and 'Object' 
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.Web.Query.Dynamic.ParseException: Operator '==' incompatible with operand types 'Int32' and 'Object'
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: 

[ParseException: Operator '==' incompatible with operand types 'Int32' and 'Object']
   System.Web.Query.Dynamic.ExpressionParser.CheckAndPromoteOperands(Type signatures, String opName, Expression& left, Expression& right, Int32 errorPos) +487761
   System.Web.Query.Dynamic.ExpressionParser.ParseComparison() +577
   System.Web.Query.Dynamic.ExpressionParser.ParseLogicalAnd() +25
   System.Web.Query.Dynamic.ExpressionParser.ParseLogicalOr() +25
   System.Web.Query.Dynamic.ExpressionParser.ParseExpression() +22
   System.Web.Query.Dynamic.ExpressionParser.Parse(Type resultType) +25
   System.Web.Query.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) +45
   System.Web.Query.Dynamic.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) +67
   System.Web.Query.Dynamic.DynamicQueryable.Where(IQueryable source, String predicate, Object[] values) +62
   System.Web.UI.WebControls.DynamicQueryableWrapper.Where(IQueryable source, String predicate, Object[] values) +14
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelectExpressions(IQueryable source, IDictionary`2 whereValues, IOrderedDictionary orderByOrderedValues, IDictionary`2 groupByValues, IDictionary`2 orderGroupsByValues, IDictionary`2 selectNewValues) +288
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelectQuery(LinqDataSourceSelectEventArgs selectEventArgs, Object selectResult, Object table, Boolean storeOriginalValues) +327
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +457
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   System.Web.UI.WebControls.ListView.PerformSelect() +57
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.ListView.CreateChildControls() +55
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +44
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
The Default.aspx page from the PhotoAlbums:
Code:
<%@ Page Title="All Photo Albums" Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<%--    (R)DBying Technologies
--%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMainContent" Runat="Server">
   <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
   <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
      DataSourceID="LinqDataSource1" DataTextField="Name" DataValueField="Id">
   </asp:DropDownList>
   <br />
   
      <asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" 
         DataSourceID="LinqDataSource2" onitemcreated="ListView1_ItemCreated">
         <ItemTemplate>
            <li style="">
               <%-- an image control to display the picure --%>
               <asp:Image ID="Image1" runat="server" 
                          ImageUrl='<%# Eval("ImageUrl") %>'
                          ToolTip='<%# Eval("Tooltip") %>' />
               
               <%-- a text to provide a description below the picure --%>
               <asp:Label ID="DescriptionLabel" runat="server" 
                  Text='<%# Eval("Description") %>' /><br />
               <asp:Button ID="DeleteButton" CommandName="Delete" runat="server" Text="Delete" />
            </li>
         </ItemTemplate>
         
         <EmptyDataTemplate>
            No data was returned.
         </EmptyDataTemplate>
         
         <LayoutTemplate>
            <ul class="itemContainer">
               <li ID="itemPlaceholder" runat="server" />
            </ul>
            <div style="">
               <asp:DataPager ID="DataPager1" runat="server" PageSize="3">
                  <Fields>
                     <%-- NextPreviousPager --%>
                     <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                        ShowLastPageButton="True" />
                     <%-- For Numeric Pager, uncomment the following --%>
                     <%--<asp:NumericPagerField NextPageText="..." PreviousPageText="..." />--%>
                  </Fields>
               </asp:DataPager>
            </div>
         </LayoutTemplate>
            
            
            
      </asp:ListView>
      
      <%-- comment --%>
      <asp:LinqDataSource ID="LinqDataSource2" runat="server" 
            ContextTypeName="LanicalDataContext" 
            TableName="Pictures" 
            Where="PhotoAlbumId == @PhotoAlbumId" EnableDelete="True">
            
         <%-- WHERE parameter(s):
          - ControlID    -- the control from which the parameter is taken for the WHERE clause
          - Name         -- the name of the PK column in the table of interest
          - PropertyName -- the corresponding value/parameter associated w/ the selected item in the drop down list, 
                              to replace @PhotoAlbumId, in the WHERE stmt above --%>
         <WhereParameters>
            <asp:ControlParameter 
               ControlID="DropDownList1" 
               Name="PhotoAlbumId" 
               PropertyName="SelectedValue" Type="Int32" />
         </WhereParameters>
      </asp:LinqDataSource>
      
      <%-- comment --%>
      <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
            ContextTypeName="LanicalDataContext" 
            Select="new (Id, Name)" 
            TableName="PhotoAlbums">
      </asp:LinqDataSource>
      
            </ContentTemplate>
   </asp:UpdatePanel>
</asp:Content>
and the .cs file is
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
 

public partial class Default : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
    {
       switch (e.Item.ItemType)
       { 
          case ListViewItemType.DataItem:
             Button deleteButton = (Button)e.Item.FindControl("DeleteButton");
             deleteButton.Visible=Roles.IsUserInRole("Managers");
             break;
          default:
             break;
       }
    }
}
Reply With Quote
  #2 (permalink)  
Old February 26th, 2011, 08:38 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Not sure what the problem is. I copied and pasted your code into my project and after changing the name of the placeholder and the ContextTypeName, the code ran fine.

Are you running this in Visual Studio 2008? And do you have the latest service packs applied (I have on my machine).

Otherwise, I can only image something is not right with the LinqToSql data source. Is the database schema alright (e.g. column types, primairy keys and so on)?

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!
Reply With Quote
  #3 (permalink)  
Old April 26th, 2011, 08:28 AM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get this same issue but I am using VWD 2010 Express. Is there a difference between 2008 and 2010 in regards to the way this is handled? Also could it be an issue of Web App vs. Web Site?

thanks
Reply With Quote
  #4 (permalink)  
Old April 26th, 2011, 11:20 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Are you using a web app? The sample site from the book requires a web site app.

But that shouldn't matter for this code though. Can you post the code for the page? Also, can you check if the code works fine with the database and L2S model that comes with the book? There might be a problem with your database and subsequently with the model.

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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch12, TIO p397: Exception in execution mkaftor BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 January 25th, 2011 04:57 AM
Code for Chpt.2-Wrox File Share is missing Default.aspx and Default.aspx.vb bzoni BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 October 23rd, 2009 02:39 PM
can't view my aspx page in browser Newbieasp BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 August 10th, 2009 03:29 AM
Query in a browser/address bar i.e. default.aspx?i takwirira ASP.NET 2.0 Basics 1 June 12th, 2008 07:58 AM
Page 228 TIO 5 Fixtures.aspx [VB] bcr212 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 May 24th, 2006 06:55 AM



All times are GMT -4. The time now is 05:28 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.