1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom user controls interoperability

Custom user controls interoperability

3 posts, 1 answered
  1. Robert
    Robert avatar
    70 posts
    Registered:
    05 Feb 2009
    24 Mar 2010
    Link to this post
    Hello, I'm developing simple ecommerce module where I have two custom user controls: ProductDetail and ShoppingCartStatus. I'd like them to communicate between each other so that when I click 'add to cart' button in ProductDetail, the ShoppingCartStatus will be updated e.g. count of items will be increased. This could be accomplished via postback or even better using ajax.
    I'm thinking about storing the state (items in cart) in either cookies or session and I need somehow to let ShoppingCartStatus know that the state is updated.
    What would be the best solution?

    Thanks!

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Mar 2010
    Link to this post
    Hello Robert,

    You can use QueryString, Cookies, Session or persist the value in hidden fileld

    Below is sample code that uses QueryStrings

    Example:

    Custom control 1 -  process request.

    protected  override void  InitializeControls(System.Web.UI.Control controlContainer)
        {
            base.InitializeControls(controlContainer);
            this.buttonControl.Click += new EventHandler(buttonControl_Click);
            this.buttonControl2.Click += new EventHandler(buttonControl2_Click);
        }
      
        void buttonControl_Click(object sender, EventArgs e)
        {
            this.Page.Response.Redirect(this.Page.Request.Url.PathAndQuery + "?something=1");
        }
      
        void buttonControl2_Click(object sender, EventArgs e)
        {
     
            this.Page.Response.Redirect(this.Page.Request.Url.PathAndQuery + "?something=2");
        }


    Custom control 2 - displays the data:

    protected  override void InitializeControls(System.Web.UI.Control controlContainer)
    {
        base.InitializeControls(controlContainer);
        if (this.Page != null && this.Page.Request.QueryString["something"] != null)
        {
            int number = Int32.Parse(this.Page.Request.QueryString["something"]);
            switch (number)
            {
                case 1:
                    this.labelControl.Text = "My something 1";
                    break;
                case 2:
                    this.labelControl.Text = "My something 2";
                    break;
            }
        }
    }


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  3. Robert
    Robert avatar
    70 posts
    Registered:
    05 Feb 2009
    24 Mar 2010
    Link to this post
    Hi Ivan,
    thanks for super fast answer :)
    This is exactly what I was looking for.


Register for webinar
3 posts, 1 answered