Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Justesen 436 posts 203 karma points
    Feb 18, 2010 @ 07:51
    Simon Justesen
    0

    Let one usercontrol update another?

    Hi guys,

    I'm developing a small webshop, everything has been running smoothly so far, but now I need to update a literal control 'minicart1' every time the user clicks to put something in the basket. This only works when I manually press F5.

    I have tried putting the controls inside an updatepanel w/ partial rendering enabled and use a trigger to notify the literal control about the change. But then I get a YSOD saying that the literal control 'minicart1' cannot be found.

    I should mention that the shop controls are inside an iframe and the minicart is in the parent window. Tried moving the shop controls out of the iframe and onto the main page but it doesn't help.

    I can't figure out how to solve this - could it be related to the way umbraco caches pages?

  • Tom Maton 387 posts 660 karma points
    Feb 18, 2010 @ 10:11
    Tom Maton
    0

    Simon,

    You may have to reference the add to basket user control in the minicart user control and expose the properties.

    A great example can be found here.

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=155

    Tom

  • Simon Justesen 436 posts 203 karma points
    Feb 22, 2010 @ 15:06
    Simon Justesen
    0

    Hi Tom, thanks for your reply! :) The problem is not so much getting the content of the cart, but to trigger the update at the right time. I'm building a custom event for this purpose, so hopefully that will do the trick. 

  • Jesper Hauge 298 posts 487 karma points c-trib
    Feb 22, 2010 @ 16:19
    Jesper Hauge
    0

    I've solved this by coding a ShoppingBasket calls that holds the cart data, storing this ShoppingBasket in a session variable, and then having a BasketStatus usercontrol that loads the session basket and renders content from the data in the session variable ShoppingBasket on page load.

    Regards
    Jesper Hauge

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Feb 22, 2010 @ 23:03
    Aaron Powell
    0

    Check out Cross Presenter Messaging as a feature of WebForms MVP. It's the way I'd go about it (and the guys who wrote it have it running a large Australian online shop).
    http://wiki.webformsmvp.com/index.php?title=Feature_walkthroughs

     

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Feb 23, 2010 @ 12:01
    Ismail Mayat
    0

    Simon,

    I did something on a site ages ago. If I remember rightly I think from the source control I did 

    targetControl  somecontrol =  this.Page.findcontrol("idoftarget") as targetControl

    I had reference to the target in the source so that the casting worked.  The target also had public method to re init a cart pulled from session.

    Regards

    Ismail

  • Simon Justesen 436 posts 203 karma points
    Feb 27, 2010 @ 15:21
    Simon Justesen
    0

    Thanks guys, I'll take a look at your suggestions :)

    Jesper, your solution sounds very similar to mine, but somehow it's not working
    Ismail, tried something similar, but keeps getting the dreaded "object not set to an instance of an object", but I'll check the references. Even tried this.Page.Master.FindControl().. etc.

  • Jesper Hauge 298 posts 487 karma points c-trib
    Mar 01, 2010 @ 12:49
    Jesper Hauge
    0

    Hi Simon

    I've attached the code of my basketstatus control here, maybe, there's some ideas in it for you.

    ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BasketStatus.ascx.cs"
        Inherits="LarsenControls.BasketStatus" %>
    <div class="sidebarItem">
        <div class="header basketHeader">
            Indkøbskurv</div>
        <div class="content">
            <p>
                <asp:Literal ID="litBasket" runat="server" /></p>
            <p><a id="lnkBasket" runat="server" class="basketLink" visible="false">Gå til indkøbskurven &raquo;</a></p>
        </div>
    </div>
    

    codebehind:

    using System;
    using System.Configuration;
    using System.Web.UI;
    using JmNet.Shop;
    
    namespace LarsenControls
    {
        public partial class BasketStatus : UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }
    
            protected override void OnPreRender(EventArgs e)
            {
                GetBasketText();
                base.OnPreRender(e);
            }
    
            private void GetBasketText()
            {
                Basket basket = GetBasket();
                Trace.Warn("Basket fetched, Items: " + basket.ItemCount.ToString());
                if (basket.ItemCount == 0)
                {
                    litBasket.Text = ConfigurationManager.AppSettings["EmptyBasketText"];
                    lnkBasket.Visible = false;
                    return;
                }
                string template = ConfigurationManager.AppSettings["NonemptyBasketText"].Replace("[br]", "<br />");
                litBasket.Text = string.Format(template, basket.ItemCount, basket.GetTotal().ToString("C"));
                lnkBasket.HRef = ConfigurationManager.AppSettings["BasketPage"];
                lnkBasket.Visible = true;
            }
    
            private Basket GetBasket()
            {
                if (!string.IsNullOrEmpty(Request["basketid"]))
                {
                    var newBasket = new Basket();
                    newBasket.PopulateFromDb(Request["basketid"]);
                    return newBasket;
                }
                if (Session["Basket"] != null)
                    return Session["Basket"] as Basket;
                return new Basket();
            }
        }
    }

    As far as I remember it was necessary to do the deed in the PreRender method, instead of Page_Load, to get it all working, maybe this is your pain point?

    Regards
    Jesper Hauge

  • techUsr 8 posts 28 karma points
    Jul 16, 2010 @ 13:39
    techUsr
    0

    Hi ,

    I want to use the control/datatype in a user control from another usercontrol.I tried doing it with Page.FindControl() but that does not work as the UserControl Id is changed.

    Can anybody help me with this?

    Thanks,

    /Brahadeesh.

Please Sign in or register to post replies

Write your reply to:

Draft