Thread: Wrox CMS in C#
View Single Post
  #7 (permalink)  
Old February 24th, 2007, 06:36 AM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi .Netster,

The code in the Content class looks fine to me. There are, however, a few other issues.

First of all, all your pages have
instead of
in the page directive at the top. Use site-wide Search and Replace to change them all. With the setting to false, the default event wiring won't work. .NET can "wire up" standard events by its name, like Page_Load which handles the Load event of the Page. It only does that with the setting to true. In your current pages, none of the standard events like Page_Load will fire.

This is related to your question:
quote:Does VB.Net not require the event handlers applied to the controls in the aspx files?
Earlier in the thread you said you removed all the Handles clauses from the code. That's the way VB does the event wiring. It basically says: this method "handles" some event for some control. So, when you, for example, double click a button, you get a method signature with a Handles clause in VB, while in C# you get the following code in the <asp:Button />
There are a few more issues in your code.

In the ContentList page, you don't have the handler set up for the RowCommand, so you won't get the Delete confirmation. Add this code to gvContent:
Finally, there's another issue in the same page in the gvContent_RowCommand handler. Currently you have this:
int recordIndex;
int recordId;
recordIndex = Convert.ToInt32(e.CommandArgument);
recordId = Convert.ToInt32(gvContent.DataKeys[recordIndex].Value);
Notice you're not adding the recordId to the QueryString. So, whatever row you click, you always redirect to id=

Change the last line to:
Response.Redirect("AddEditContent.aspx?Id=" + recordId);
(and make the other changes) and you'll find that a lot of things will start working now (and hopefully start to make sense as well).

Cheers and good luck,

Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.