Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics 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 July 22nd, 2008, 02:37 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Subscribe to event in another control on a page

Hi,

I have a forum page called Chat.aspx which consist of the following controls:

Message
MessageSubmit
PostList

PostList is a repeater containing Message & MessageSubmit controls.

I include single instances of Message & MessageSubmit controls in Chat.aspx to display the first post (it's a Q&A type forum).

Subsequent messages are displayed in the PostList control.

The problem I have is that when I submit a reply to the first post (in Chat.aspx) an event is fired in MessageSubmit which is handled in Chat.aspx and binds the data to the Message control but the event it is supposed to fire and which Postlist should handle is always null so it doesn't fire and Postlist does not not refresh to display the new post.

It looks a bit like this:
Code:
public event NewPostCreatedHandler NewPostCreated;

protected void FirstPostReply_NewPostCreated(object sender, int postid)
{
  BindPost();
  if (NewPostCreated != null)
  {
    NewPostCreated(sender, postid);
  }
}
Any ideas what I might be doing wrong?
__________________
http://www.thewebsiteshop.co.uk
  #2 (permalink)  
Old July 22nd, 2008, 06:46 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Simple answer: you can't do this.

What you are asking for is "push" technology. This died years ago (did it ever live?). Pages are never alive together in the way you want them to be. You need to use server polling to check for updates to the chat. You could do this with an AJAX timer.

-Peter
compiledthoughts.com
  #3 (permalink)  
Old July 23rd, 2008, 07:43 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you sure? Maybe I haven't explained it very clearly.

The submit event in MessageSubmit triggers the NewPostCreated event handled by FirstPostReply_NewPostCreated in Chat.aspx. After processing the MessageSubmit events shouldn't the page process PostList events (if there are any) as it's the next control on the page.

I just want to raise an event in FirstPostReply_NewPostCreated to be handled in PostList which page processing should be getting around to next.

http://www.thewebsiteshop.co.uk
  #4 (permalink)  
Old July 23rd, 2008, 11:48 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

My bad... I misread the subject. I thought you were trying to gets one page to trip and event handler on another page. I hereby retrack my previous post.

Yes, you certainly can have one control trigger an event on another, it's just a matter of wiring up the events. Something like this would be needed in an early point of your page (page_load should be fine):
Code:
myControlToWatch.MyEvent += new NewPostCreatedHandler(myControlToListen.PublicEventHandler);
Good decoupling practices would dictate that you keep the specific event signature away from the listening control:
Code:
myControlToWatch.MyEvent += new NewPostCreatedHandler(myLocalHandlerMethod);

protected void myLocalHandlerMethod(object sender, int postid){
   myControlInstanceToInformOfChange.HeySomethingHappened(parameters...);
}
-Peter
compiledthoughts.com
  #5 (permalink)  
Old July 24th, 2008, 03:48 AM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter,

You didn't misread the subject, I changed it when I realised that it was misleading. I just hadn't explained it very well.

I'll give your solution a go and let you know how I get on.

Best Wishes,

Paul
 


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
What if I need control value before event is fired pauliehaha ASP.NET 3.5 Basics 9 May 22nd, 2008 12:51 PM
Subscribe to topic functionality miltonsnider BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 December 12th, 2006 11:55 AM
User Control with my event ALGNET .NET Framework 2.0 1 May 2nd, 2006 05:56 PM
Subscribe to a Forum? ababb Forum and Wrox.com Feedback 1 December 16th, 2004 05:29 AM
subscribe.aspx groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 0 October 22nd, 2004 09:59 AM



All times are GMT -4. The time now is 10:58 AM.


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