views:

12

answers:

0

Hi

I want to achive the following behavior:

when a user clicks on a button in an control some data will be processed in background and another control from the page will be updated when the job is finished (both controls are in updatepanels (or not) -> doesn't work anyway). My code looks something like this:

Control1 (which makes the call): contains a normal Button in the aspx page with an OnClick Event definded: protected void Button1_Clicked(object sender, EventArgs e) {
Helper.GetCurrentCart().AddProductToCart(productid); } where Helper.GetCurrentCart() returns an object (Cart) that is saved in session. (or creates one and saves in session for later use)

Cart Object has following code:

namespace xxx { public class Cart {

   public Cart()
   {
   }

public delegate void CartModifiedEventHandler(CartModifiedEventArgs e); //CartModifiedEventArgs -> custom event args public event CartModifiedEventHandler OnCartModified;

   private void TriggerCartModified()
   {

       if (this.OnCartModified != null)
           this.OnCartModified.Invoke(new WarenkorbModifiedEventArgs());
        //or: this.OnCartModified(new WarenkorbModifiedEventArgs());

   }

    public void AddProductToCart(int productId)
    {
       //do some data processing             
          TriggerCartModified();
        }
    }

} } and Control2: namespace xxx { public partial class QuickCart: System.Web.UI.UserControl {

    private xxx.CartModifiedEventHandler carteventhandler;

    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
        {
            carteventhandler= new CartModifiedEventHandler(OnCartModified);

        }
        Helper.GetCurrentCart().OnCartModified += carteventhandler;

    }

    void OnCartModified(CartModifiedEventArgs e)
    {
        cartInfo.Text = "updated!!!!"; 
    }

}

}

almost everything works -> event will be raised but the problem is that this happens in another thread or in another instance of Control2 - and the one on the page will not be updated.

is it possible to make this work?

many thanks

Victor