p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   Pure frustration (http://p2p.wrox.com/showthread.php?t=83662)

vbboyd May 14th, 2011 05:02 PM

Pure frustration
 
<script type="text/javascript">
$(function () {
$('.GridView tr:odd:not(.GridViewPagerStyle)').addClass('GridVi ewAlternatingRowStyle');
});
<

I get a javascript error that says $ is not defined. This makes no sense because it in the management master master page and it still gives me this error. This is pure insanity and this should not be happening.

Imar May 14th, 2011 05:29 PM

Hi there,

As you can see by browsing this forum, you can see I am very open to criticism and feedback on my books. However, it has to be constructive. And your comment doesn't qualify as such. Burn it and write a very very bad review on Amazon.com because you made a mistake somewhere? That makes no sense to me at all.

So, if you want to give this worthless book another shot and make this work, try this instead and I'll point you to your error:

1. Post the code for the master page
2. Post the code for the page
3. Make sure the jQuery script is located in the correct folder and is named as described in the book.
4. Tell me where you get the error (in visual studio or in the browser)

With this information, the problem can be fixed in minutes.

Cheers,

Imar

vbboyd May 14th, 2011 05:50 PM

How do I post the code for the master page?
 
Do I put the code in here for you? I don't understand.

vbboyd May 14th, 2011 05:51 PM

How do I post the [code] for the masterpage. Do I post it in here? I am very confused!

vbboyd May 14th, 2011 05:51 PM

How do I reply
 
Do I post what you want in here? I am very confused.

vbboyd May 14th, 2011 06:00 PM

Dude I am using YOUR Code straight from the website. It still throws a javascript error when I try to run it gives me a run time error that says that $ is not recognized or is undefined. or something like that.
Code:

All I did was copy and paste your code.
It dies right here at run time. It compiles fine otherwise.
I get a javascript error that says $ not defined.
<script type="text/javascript">
      $(function () {
          $('.GridView tr:odd:not(.GridViewPagerStyle)').addClass('GridViewAlternatingRowStyle');
      });
  </script>
<%@ Page Title="Planet Wrox - Management - Genres" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="Genres.aspx.cs" Inherits="Management_Genres" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
  <asp:Label ID="ErrorMessage" runat="server" CssClass="ErrorMessage" EnableViewState="False"></asp:Label>
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="GridView1_RowDataBound">
    <Columns>
      <asp:TemplateField ShowHeader="False">
        <EditItemTemplate>
          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
          &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
          &nbsp;<asp:LinkButton ID="DeleteLink" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
        </ItemTemplate>
        <ItemStyle Width="100px" />
      </asp:TemplateField>
      <asp:BoundField ItemStyle-Width="200px" DataField="Name" HeaderText="Name" SortExpression="Name">
        <ItemStyle Width="200px"></ItemStyle>
      </asp:BoundField>
      <asp:BoundField DataField="SortOrder" HeaderText="SortOrder" SortExpression="SortOrder" />
    </Columns>
  </asp:GridView>
  <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
    <Fields>
      <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
      <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
      <asp:BoundField DataField="SortOrder" HeaderText="SortOrder" SortExpression="SortOrder" />
      <asp:CommandField ShowInsertButton="True" />
    </Fields>
  </asp:DetailsView>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" DeleteCommand="DELETE FROM [Genre] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Genre] ([Name], [SortOrder]) VALUES (@Name, @SortOrder)" ProviderName="<%$ ConnectionStrings:PlanetWroxConnectionString1.ProviderName %>" SelectCommand="SELECT Genre.Id, Genre.Name, Genre.SortOrder, COUNT(Review.Id) AS NumberOfReviews FROM Genre LEFT OUTER JOIN Review ON Genre.Id = Review.GenreId GROUP BY Genre.Id, Genre.Name, Genre.SortOrder" UpdateCommand="UPDATE [Genre] SET [Name] = @Name, [SortOrder] = @SortOrder WHERE [Id] = @Id" OnDeleted="SqlDataSource1_Deleted">
    <DeleteParameters>
      <asp:Parameter Name="Id" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
      <asp:Parameter Name="Name" Type="String" />
      <asp:Parameter Name="SortOrder" Type="Int32" />
    </InsertParameters>
    <UpdateParameters>
      <asp:Parameter Name="Name" Type="String" />
      <asp:Parameter Name="SortOrder" Type="Int32" />
      <asp:Parameter Name="Id" Type="Int32" />
    </UpdateParameters>
  </asp:SqlDataSource>
  <script type="text/javascript">
      $(function () {
          $('.GridView tr:odd:not(.GridViewPagerStyle)').addClass('GridViewAlternatingRowStyle');
      });
  </script>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using System.Data.SqlClient;

public partial class Management_Genres : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.DataRow:
                DataRowView myDataRowView = (DataRowView)e.Row.DataItem;
                if (Convert.ToInt32(myDataRowView["NumberOfReviews"]) > 0)
                {
                    LinkButton deleteLink = e.Row.FindControl("DeleteLink") as LinkButton;
                    if (deleteLink != null)
                    {
                        deleteLink.Enabled = false;
                    }
                }
                break;
        }
    }

    protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (e.Exception != null && e.Exception is SqlException)
        {
            SqlException myException = (SqlException)e.Exception;
            if (myException.Number == 547)
            {
                ErrorMessage.Text = @"Sorry, you can't delete this genre because it has associated reviews that you need to delete first.";
                e.ExceptionHandled = true;
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using System.Data.SqlClient;

public partial class Management_Genres : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.DataRow:
                DataRowView myDataRowView = (DataRowView)e.Row.DataItem;
                if (Convert.ToInt32(myDataRowView["NumberOfReviews"]) > 0)
                {
                    LinkButton deleteLink = e.Row.FindControl("DeleteLink") as LinkButton;
                    if (deleteLink != null)
                    {
                        deleteLink.Enabled = false;
                    }
                }
                break;
        }
    }

    protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (e.Exception != null && e.Exception is SqlException)
        {
            SqlException myException = (SqlException)e.Exception;
            if (myException.Number == 547)
            {
                ErrorMessage.Text = @"Sorry, you can't delete this genre because it has associated reviews that you need to delete first.";
                e.ExceptionHandled = true;
            }
        }
    }
}


vbboyd May 14th, 2011 06:01 PM

Dude I am using YOUR stuff straight from the website. It still throws a javascript error when I try to run it gives me a run time error that says that $ is not recognized or is undefined. or something like that.
Code:

All I did was copy and paste your code.
It dies right here at run time. It compiles fine otherwise.
I get a javascript error that says $ not defined.
<script type="text/javascript">
      $(function () {
          $('.GridView tr:odd:not(.GridViewPagerStyle)').addClass('GridViewAlternatingRowStyle');
      });
  </script>
<%@ Page Title="Planet Wrox - Management - Genres" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="Genres.aspx.cs" Inherits="Management_Genres" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
  <asp:Label ID="ErrorMessage" runat="server" CssClass="ErrorMessage" EnableViewState="False"></asp:Label>
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="GridView1_RowDataBound">
    <Columns>
      <asp:TemplateField ShowHeader="False">
        <EditItemTemplate>
          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
          &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
        </EditItemTemplate>
        <ItemTemplate>
          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
          &nbsp;<asp:LinkButton ID="DeleteLink" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
        </ItemTemplate>
        <ItemStyle Width="100px" />
      </asp:TemplateField>
      <asp:BoundField ItemStyle-Width="200px" DataField="Name" HeaderText="Name" SortExpression="Name">
        <ItemStyle Width="200px"></ItemStyle>
      </asp:BoundField>
      <asp:BoundField DataField="SortOrder" HeaderText="SortOrder" SortExpression="SortOrder" />
    </Columns>
  </asp:GridView>
  <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
    <Fields>
      <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
      <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
      <asp:BoundField DataField="SortOrder" HeaderText="SortOrder" SortExpression="SortOrder" />
      <asp:CommandField ShowInsertButton="True" />
    </Fields>
  </asp:DetailsView>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" DeleteCommand="DELETE FROM [Genre] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Genre] ([Name], [SortOrder]) VALUES (@Name, @SortOrder)" ProviderName="<%$ ConnectionStrings:PlanetWroxConnectionString1.ProviderName %>" SelectCommand="SELECT Genre.Id, Genre.Name, Genre.SortOrder, COUNT(Review.Id) AS NumberOfReviews FROM Genre LEFT OUTER JOIN Review ON Genre.Id = Review.GenreId GROUP BY Genre.Id, Genre.Name, Genre.SortOrder" UpdateCommand="UPDATE [Genre] SET [Name] = @Name, [SortOrder] = @SortOrder WHERE [Id] = @Id" OnDeleted="SqlDataSource1_Deleted">
    <DeleteParameters>
      <asp:Parameter Name="Id" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
      <asp:Parameter Name="Name" Type="String" />
      <asp:Parameter Name="SortOrder" Type="Int32" />
    </InsertParameters>
    <UpdateParameters>
      <asp:Parameter Name="Name" Type="String" />
      <asp:Parameter Name="SortOrder" Type="Int32" />
      <asp:Parameter Name="Id" Type="Int32" />
    </UpdateParameters>
  </asp:SqlDataSource>
  <script type="text/javascript">
      $(function () {
          $('.GridView tr:odd:not(.GridViewPagerStyle)').addClass('GridViewAlternatingRowStyle');
      });
  </script>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using System.Data.SqlClient;

public partial class Management_Genres : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.DataRow:
                DataRowView myDataRowView = (DataRowView)e.Row.DataItem;
                if (Convert.ToInt32(myDataRowView["NumberOfReviews"]) > 0)
                {
                    LinkButton deleteLink = e.Row.FindControl("DeleteLink") as LinkButton;
                    if (deleteLink != null)
                    {
                        deleteLink.Enabled = false;
                    }
                }
                break;
        }
    }

    protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (e.Exception != null && e.Exception is SqlException)
        {
            SqlException myException = (SqlException)e.Exception;
            if (myException.Number == 547)
            {
                ErrorMessage.Text = @"Sorry, you can't delete this genre because it has associated reviews that you need to delete first.";
                e.ExceptionHandled = true;
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using System.Data.SqlClient;

public partial class Management_Genres : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.DataRow:
                DataRowView myDataRowView = (DataRowView)e.Row.DataItem;
                if (Convert.ToInt32(myDataRowView["NumberOfReviews"]) > 0)
                {
                    LinkButton deleteLink = e.Row.FindControl("DeleteLink") as LinkButton;
                    if (deleteLink != null)
                    {
                        deleteLink.Enabled = false;
                    }
                }
                break;
        }
    }

    protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e)
    {
        if (e.Exception != null && e.Exception is SqlException)
        {
            SqlException myException = (SqlException)e.Exception;
            if (myException.Number == 547)
            {
                ErrorMessage.Text = @"Sorry, you can't delete this genre because it has associated reviews that you need to delete first.";
                e.ExceptionHandled = true;
            }
        }
    }
}


vbboyd May 14th, 2011 06:05 PM

Code:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Management.master.cs" Inherits="MasterPages_Management" %>
<!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">
      <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
  </asp:ContentPlaceHolder>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <div style="width: 200px; float: left;">
      <ul>
        <li><a href="~/Management/Default.aspx" runat="server">Management Home</a></li>
        <li><a href="~/Management/Genres.aspx" runat="server">Manage Genres</a></li>
        <li><a href="~/Management/Reviews.aspx" runat="server">Manage Reviews</a></li>
      </ul>
    </div>
    <div style="width: 750px; float: left;">
      <asp:ContentPlaceHolder ID="cpMainContent" runat="server">
      </asp:ContentPlaceHolder>
    </div>
  </div>
  </form>
</body>
</html>


vbboyd May 14th, 2011 06:10 PM

I stand corrected.
 
You know what? I owe you an appology. My bad. I way over-reacted. Must be the Irish in me. Sorry about that. I found the error and it was something really stupid. I placed the line for the jquery in managemaster page in the wrong place. I fixed this problem. A very simple mistake led to a big error. I was wrong I stand corrected. My bad once again.

Imar May 14th, 2011 06:32 PM

That's OK. You're not the first one to run into issues like this. After all, you bought a Beginners book. You are, however, the first, and hopefully the last, person to post a comment about the book in such an extremely rude way.

Imar


All times are GMT -4. The time now is 01:44 PM.

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