Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 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
  #1 (permalink)  
Old February 1st, 2007, 07:14 PM
Authorized User
 
Join Date: Jan 2007
Location: Milano, , Italy.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Wrox Blog - Save Button & Refresh category

Hi all,

I've noticed that after creating/modifing a Blog Entry, when I click "SAVE" button the category repeater control does not report correct data. eg. If a create a new Blog Entry in "Personal" category this is not added.

I see that on Page Load event of the BlogEntriesFilter control, a query to categories and DataBind are made in case on NOT PostBack.

I've placed this 2 lines of code
repCategories.DataSource = BlogManager.GetCategories()
repCategories.DataBind()
out of the "Not Page.IsPostBack " code, but nothing is changed.

What I'm doing wrong? How is the best to force a refresh of the repCategories asp control after the "SAVE" button event?

Alan
__________________
Alan
  #2 (permalink)  
Old February 2nd, 2007, 02:52 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Alan,

The problem is related to the order of events; Page_Load fires before the other events.

There are two ways to fix this:

1. Create a method on the User Control called UpdateList for example. Inside this method call GetCategories() and DataBind() as in the code below to update the list.
In the Save button's Click event, call UpdateList on the user control to force it to update the list.

2. Simply do a full redirect after the save operation:

  Response.Redirect("~/")

should do the trick as well.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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.
  #3 (permalink)  
Old February 2nd, 2007, 07:36 AM
Authorized User
 
Join Date: Jan 2007
Location: Milano, , Italy.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I created a method on BlogEntriesFilter.ascx
private void UpdateCategoriesList()
    {
        repCategories.DataSource = BlogManager.GetCategories();
        repCategories.DataBinding();
    }

but the compiler display a Build error:
"The event 'System.Web.UI.Control.DataBinding' can only appear on the left hand side of += or -="

I've not found many references for understaning this error....

Alan
  #4 (permalink)  
Old February 2nd, 2007, 07:49 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

DataBinding() is an event. Instead, you need to call DataBind()

private void UpdateCategoriesList()
{
  repCategories.DataSource = BlogManager.GetCategories();
  repCategories.DataBind();
}

Also, to be able to call the method from another page, you need to make it public instead of private.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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.
  #5 (permalink)  
Old February 2nd, 2007, 09:02 AM
Authorized User
 
Join Date: Jan 2007
Location: Milano, , Italy.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, my error... and now also the method is pubblic.

I found to implement this more complex, that I imagined. My knowledge on ASP.NET is yet too low.

I found very difficult to understand how to invoke the UpdateCategoriesList() in BlogEntriesFilter user control from BlogEntries user control. As the SAVE button click event is in the BlogEntries user control.

Try to find help on-line but the question seems to be complex.
Any suggestion?

Thanks a lot for the graet support you already give me!
Alan




Alan
  #6 (permalink)  
Old February 2nd, 2007, 10:12 AM
Authorized User
 
Join Date: Jan 2007
Location: Milano, , Italy.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Addendum on my tests.
I tryed to implement this "category refresh" in Page_Load event of Default.aspx.
protected void Page_Load(object sender, EventArgs e)
    {
        if (BlogEntriesFilter1.IsPostBack)
        {
            BlogEntriesFilter1.UpdateCategoriesList();
        }
    }

With debugger I've seen that after the save button click is clicked the PostBack is invoked the UpdateCategoriesList method is called, but unfortunatly the result is still the same. No update was displayed in the renderd page.

Alan
  #7 (permalink)  
Old February 2nd, 2007, 11:37 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Alan,

Yeah, it's a difficult problem, because the functionality is embedded in User Controls. To promote reuse, you can't strongly couple the controls. So, although you technically could, you shouldn't find a reference in control A to control B and call some method.

Instead, you should base this on Events. The BlogEntry control should fire an Event called OnBlogEntrySaved (or whatever you want to call it). The containing page handles this event (similar to how it handles a Button's click) and then calls RefreshGridView on the other user control.

For an implementation of this, look at the WebShop chapter. The ShoppingCartView.ascx control defines an event called CartUpdated that is used to signal other parts of the application that the shopping cart has changed.

However, if you want to do this much and much simpler, simply redirect to:

Response.Redirect(Request.CurrentExecutionFilePath )

In addition, to preserve the querystring, look at GetNavigateUrl in the BlogEntriesFilter control.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrox Blog in C# madAlan BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 22 June 12th, 2011 04:09 AM
Wrox Blog tblessed23 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 16 May 14th, 2007 04:08 PM
Wrox Blog: Viewing individual blog entries Tawanda BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 7 May 7th, 2007 12:06 PM
Add category on Blog highspeedwire BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 January 26th, 2007 05:35 PM
Wrox blog suggestions nakori BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 June 15th, 2006 04:35 PM





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