Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:03 PM.


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