Results 1 to 6 of 6

Thread: [RESOLVED] Chapter 11 from Sitepoint Build Your Own Asp.Net2 Web Site

  1. #1

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Resolved [RESOLVED] Chapter 11 from Sitepoint Build Your Own Asp.Net2 Web Site

    I am trying to get the books project 7 working from chapter 11.
    Everything about the address page works fine until I hit the update button to update an address record.
    I get the following page message after doing so. I made sure to add the stored procedures UpdateEmployee and UpdateEmployeeDetails but it still gives me the error. All the previous projects as well are working fine. I can not figure out where this event ItemUpdating is coming from. I am guessing it's internal to the DetailsView Control.
    I need some direction on where to go looking to solve this error.
    Thanks in advance.

    Server Error in '/07_editing_in_detailsview' Application.
    --------------------------------------------------------------------------------

    The DetailsView 'employeeDetails' fired event ItemUpdating which wasn't handled.
    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.HttpException: The DetailsView 'employeeDetails' fired event ItemUpdating which wasn't handled.

    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:


    [HttpException (0x80004005): The DetailsView 'employeeDetails' fired event ItemUpdating which wasn't handled.]
    System.Web.UI.WebControls.DetailsView.OnItemUpdating(DetailsViewUpdateEventArg s e) +324
    System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation) +974
    System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +545
    System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +162
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
    System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +117
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
    System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +107
    System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +175
    System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Raise PostBackEvent(String eventArgument) +31
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839




    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

  2. #2

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: Chapter 11 from Sitepoint Build Your Own Asp.Net2 Web Site

    Addressbook.aspx code:
    asp.net Code:
    1. <%@ Page Language="C#" MasterPageFile="~/Dorknozzle.master" AutoEventWireup="true" CodeFile="AddressBook.aspx.cs" Inherits="AddressBook" Title="Dorknozzle Address Book" %>
    2. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    3.   <h1>Address Book</h1>
    4.   <asp:GridView id="grid" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="grid_SelectedIndexChanged">
    5.     <Columns>
    6.       <asp:BoundField DataField="Name" HeaderText="Name" />
    7.       <asp:BoundField DataField="City" HeaderText="City" />
    8.       <asp:BoundField DataField="MobilePhone"
    9.           HeaderText="Mobile Phone" />
    10.       <asp:ButtonField CommandName="Select" Text="Select" />
    11.     </Columns>
    12.   </asp:GridView><br />
    13.   <asp:DetailsView id="employeeDetails" runat="server"
    14.       AutoGenerateRows="False" OnModeChanging="employeeDetails_ModeChanging">
    15.     <Fields>
    16.       <asp:BoundField DataField="Address" HeaderText="Address" />
    17.       <asp:BoundField DataField="City" HeaderText="City" />
    18.       <asp:BoundField DataField="State" HeaderText="State" />
    19.       <asp:BoundField DataField="Zip" HeaderText="Zip" />
    20.       <asp:BoundField DataField="HomePhone"
    21.           HeaderText="Home Phone" />
    22.       <asp:BoundField DataField="Extension"
    23.           HeaderText="Extension" />
    24.       <asp:CommandField ShowEditButton="True" />
    25.     </Fields>
    26.     <HeaderTemplate>
    27.       <%#Eval("Name")%>
    28.     </HeaderTemplate>
    29.   </asp:DetailsView>
    30. </asp:Content>
    Addressbook.aspx.cs code:
    c# Code:
    1. using System;
    2. using System.Data;
    3. using System.Configuration;
    4. using System.Collections;
    5. using System.Web;
    6. using System.Web.Security;
    7. using System.Web.UI;
    8. using System.Web.UI.WebControls;
    9. using System.Web.UI.WebControls.WebParts;
    10. using System.Web.UI.HtmlControls;
    11. using System.Data.SqlClient;
    12.  
    13. public partial class AddressBook : System.Web.UI.Page
    14. {
    15.     protected void Page_Load(object sender, EventArgs e)
    16.     {
    17.         if (!IsPostBack)
    18.         {
    19.             BindGrid();
    20.         }
    21.     }
    22.     private void BindGrid()
    23.     {
    24.         // Define data objects
    25.         SqlConnection conn;
    26.         SqlCommand comm;
    27.         SqlDataReader reader;
    28.         // Read the connection string from Web.config
    29.         string connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString;
    30.         // Initialize connection
    31.         conn = new SqlConnection(connectionString);
    32.         // Create command
    33.         comm = new SqlCommand(
    34.           "SELECT EmployeeID, Name, City, State, MobilePhone FROM Employees", conn);
    35.         // Enclose database code in Try-Catch-Finally
    36.         try
    37.         {
    38.             // Open the connection
    39.             conn.Open();
    40.             // Execute the command
    41.             reader = comm.ExecuteReader();
    42.             // Fill the grid with data
    43.             grid.DataSource = reader;
    44.             grid.DataKeyNames = new string[] { "EmployeeID" };
    45.             grid.DataBind();
    46.             // Close the reader
    47.             reader.Close();
    48.         }
    49.         finally
    50.         {
    51.             // Close the connection
    52.             conn.Close();
    53.         }
    54.     }
    55.     protected void grid_SelectedIndexChanged(object sender,
    56.     EventArgs e)
    57.     {
    58.         BindDetails();
    59.     }
    60.     private void BindDetails()
    61.     {
    62.         // Obtain the index of the selected row
    63.         int selectedRowIndex = grid.SelectedIndex;
    64.         // Read the employee ID
    65.         int employeeId = (int)grid.DataKeys[selectedRowIndex].Value;
    66.         // Define data objects
    67.         SqlConnection conn;
    68.         SqlCommand comm;
    69.         SqlDataReader reader;
    70.         // Read the connection string from Web.config
    71.         string connectionString =
    72.             ConfigurationManager.ConnectionStrings[
    73.             "Dorknozzle"].ConnectionString;
    74.         // Initialize connection
    75.         conn = new SqlConnection(connectionString);
    76.         // Create command
    77.         comm = new SqlCommand(
    78.             "SELECT EmployeeID, Name, Address, City, State, Zip, " +
    79.             "HomePhone, Extension FROM Employees " +
    80.             "WHERE EmployeeID=@EmployeeID", conn);
    81.         // Add the EmployeeID parameter
    82.         comm.Parameters.Add("EmployeeID", SqlDbType.Int);
    83.         comm.Parameters["EmployeeID"].Value = employeeId;
    84.         // Enclose database code in Try-Catch-Finally
    85.         try
    86.         {
    87.             // Open the connection
    88.             conn.Open();
    89.             // Execute the command
    90.             reader = comm.ExecuteReader();
    91.             // Fill the grid with data
    92.             employeeDetails.DataSource = reader;
    93.             employeeDetails.DataKeyNames = new string[] { "EmployeeID" };
    94.             employeeDetails.DataBind();
    95.             // Close the reader
    96.             reader.Close();
    97.         }
    98.         finally
    99.         {
    100.             // Close the connection
    101.             conn.Close();
    102.         }
    103.     }
    104.     protected void employeeDetails_ModeChanging(object sender, DetailsViewModeEventArgs e)
    105.     {
    106.         // Change current mode to the selected one
    107.         employeeDetails.ChangeMode(e.NewMode);
    108.         // Rebind the grid
    109.         BindDetails();
    110.     }
    111. }
    Last edited by Hack; Nov 28th, 2011 at 01:05 PM. Reason: Added Highlight Tags

  3. #3

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: Chapter 11 from Sitepoint Build Your Own Asp.Net2 Web Site

    Ok, I am seeing now that I have to handle this updating as it's not now. I thought somehow the detailsview control had this code built into it but it's not. Ok, I'll work on this and get back if there's any more problems with it.

  4. #4

    Thread Starter
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: Chapter 11 from Sitepoint Build Your Own Asp.Net2 Web Site

    Solved it. Just had to add the code needed for udating through the update event.

  5. #5
    New Member
    Join Date
    Nov 2011
    Posts
    1

    Re: [RESOLVED] Chapter 11 from Sitepoint Build Your Own Asp.Net2 Web Site

    I might have same situation as well as yours.. You mentioned that you must add the code to the page that is working. So what is code? I need to know.

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Chapter 11 from Sitepoint Build Your Own Asp.Net2 Web Site

    Hello,

    Have you checked with the original publisher of the book to ensure that there are no corrections to the original book. Normally publisher produce an errata for each book to indicate corrections and typos once the book is published.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width