I've just discovered the cool RaiseBubbleEvent that's provided within  ASP.NET.  As the name suggests, it bubbles up event from the called  methods, to the calling methods.  So, first, here's the code and  afterwards I'll tell you why I needed to make use of it. 
private void  SomeCalledMethod() {
/* Do some processing */}
...
/* Now raise the bubble event up to the calling method.
Whoever consumes this bubble event, they will know that it's telling them to Rebind. Any phrase/word can be placed in here */
CommandEventArgs args = new CommandEventArgs("Rebind", String.Empty);
RaiseBubbleEvent(null, args);
protected
override bool OnBubbleEvent(object source, EventArgs args) {
CommandEventArgs e = (CommandEventArgs)args;}
if (e.CommandName == "Rebind")
{
//Rebind code goes here
}
return true;
 The reason that I'm having to use this code is because I'm creating a  web shop for a customer of ours and creating a shopping basket/cart.   The markup for the cart became quite long as I have 40 textboxes  allowing the customer to type in part numbers directly, instead of  browsing, so I thought I'd create a couple of user controls that could  be reused in other projects.  However, when the user clicked on the  "place all 40 items in the cart" button, it has to do some validation  etc and then if successful, the shopping cart has to be displayed, but  the logic to display the cart was in the basket.aspx page, and how was I  going to inform this page that the shopping cart needed to be  displayed. 
 So after a few suggestions from my colleagues, I tried using javascript  and window.location.reload(), then history.go(0) and finally  window.location.href=window.location.href.  Unfortunately the first two  went into an endless loop reloading the page, asking did I really want  to reload the page and the final one worked, but it just reloaded empty  controls.  So I thought, okay, I'll use & set EnableViewState in the  root for page, usercontrol and asp controls, but still no luck.  I then  came across RaiseBubbleEvent and learnt of it's magical powers!  I wish  I had been introduced to it years ago! 
 Anyway, happy bubbling! 
 
No comments:
Post a Comment