Wrox Programmer Forums
|
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 October 7th, 2010, 03:41 PM
Registered User
 
Join Date: Oct 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 11 - Try it Out Pg. 370

Hi,

I have been doing all the exercises building the Wrox website. I followed the directions in this "Try It Out" on page 370 and when I open the JQuery demo in the browser, I do not see any change in the background color of the MainContent div and nothing seems to happen when I click the Button. Also, I tried changing the theme, and apparently something is wrong because the theme does not change.

This is the code for the JQuery Demo:

Code:
<%@ Page Title="jQuery Demo" Language="C#" MasterPageFile="~/MasterPages/Frontend.master"
    AutoEventWireup="true" CodeFile="jQuery.aspx.cs" Inherits="Demos_jQuery" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
    Este espacio es el main content area.
    <input id="Button1" type="button" value="button" />
    <script type="text/javascript">
        $(document).ready(function ()
        {
            $('#MainContent').css('background-color', 'green')

            $('#Button1').click(function ()
            {
                $('#MainContent').css('background-color', 'red')
                .animate({ width: '100px', height: '800px' })
            });
        });
    </script>
</asp:Content>

And this is the code I added to the Frontend.master:

Code:
<form id="form1" runat="server" enableviewstate="True">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
        <Scripts>
            <asp:ScriptReference Path="~/Scripts/jquery-1.4.1.min.js" />
        </Scripts>
    </asp:ScriptManager>
    <div id="PageWrapper">
I compared very carefully with the final code you provide in the Chapter 11 Resources.

Thank you.

Last edited by ISE1988; October 7th, 2010 at 07:43 PM..
 
Old October 8th, 2010, 03:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

It works fine for me when I copy and paste your code in my sample application, so it must be caused by something you're not showing here. Two things I can think off:

1. jquery-1.4.1.min.js is not located in the Scripts folder.

2. Your Master Page may be different from mine. Maybe you used different capitalization on MainContent? E.g. maybe you have Maincontent or an entirely different name? If you can't figure it out, can you post the full code for the master page?

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!
 
Old October 10th, 2010, 09:14 PM
Registered User
 
Join Date: Oct 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi again and thank you for your reply. I do have the jquery-1.4.1.min.js file in the Scripts folder, so I am including the code for the master page. I find it strange that changing theme does work for the other pages in the website, but not for the jquery demo.

Code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Frontend.master.cs" Inherits="MasterPages_Frontend" %>

<!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></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server" enableviewstate="True">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
        <Scripts>
            <asp:ScriptReference Path="~/Scripts/jquery-1.4.1.min.js" />
        </Scripts>
    </asp:ScriptManager>
    <div id="PageWrapper">
        <div id="Header">
            <a href="~/" runat="server"></a>
        </div>
        <div id="MenuWrapper">
            <asp:Menu ID="Menu1" runat="server" CssClass="MainMenu" DataSourceID="SiteMapDataSource1"
                Orientation="Horizontal" StaticEnableDefaultPopOutImage="False">
            </asp:Menu>
            <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" ShowExpandCollapse="False">
                <LevelStyles>
                    <asp:TreeNodeStyle CssClass="FirstLevelMenuItems" />
                </LevelStyles>
            </asp:TreeView>
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
        </div>
        <div id="Main Content">
            <asp:SiteMapPath ID="SiteMapPath1" runat="server">
            </asp:SiteMapPath>
            <br />
            <br />
            <asp:ContentPlaceHolder ID="cpMainContent" runat="server">
            </asp:ContentPlaceHolder>
        </div>
        <div id="Sidebar">
            Select a Theme
            <br />
            <asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ThemeList_SelectedIndexChanged">
                <asp:ListItem>Monochrome</asp:ListItem>
                <asp:ListItem>DarkGrey</asp:ListItem>
            </asp:DropDownList>
            <br />
            <br />
            <br />
            <Wrox:Banner ID="Banner1" runat="server" DisplayDirection="Vertical" />
        </div>
        <div id="Footer">
            Footer Goes Here</div>
    </div>
    </form>
</body>
</html>
Thank you, again.
 
Old October 11th, 2010, 07:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
find it strange that changing theme does work for the other pages in the website, but not for the jquery demo.
Right. I thought this was about the jQuery code not working. The fact that the theme switcher doesn't work is most likely caused by the fact your page doesn't inherit BasePage. Check the Code Behind and see if the page inherits BasePage instead of System.Web.UI.Page.

Quote:
Maybe you used different capitalization on MainContent? E.g. maybe you have Maincontent or an entirely different name?
<div id="Main Content">

See that space between Main and Content? That's why the jQuery doesn't work....

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:
ISE1988 (October 11th, 2010)
 
Old October 11th, 2010, 03:12 PM
Registered User
 
Join Date: Oct 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

You are sooo right! ... and I am so embarrassed. Thank you very much!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 11 semantic error pg 295 notig BOOK: Beginning Visual C# 2010 0 September 28th, 2010 01:29 PM
Ch 8 pg 282 Step 11 workib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 May 26th, 2008 04:19 PM
chapter 11 figure 11-7 relative positioning pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 November 29th, 2007 06:11 AM
Chapter 11 Pg 334 Running Balance JackalBW BOOK: Access 2003 VBA Programmer's Reference 0 November 29th, 2007 04:07 AM
Page 370 - New ContextMenu MajorD BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 July 25th, 2007 10:26 AM





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