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?
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.
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.
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.
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?
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.
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?
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
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.
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
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
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
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.
Hi Simon
I've attached the code of my basketstatus control here, maybe, there's some ideas in it for you.
ascx:
codebehind:
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
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.
is working on a reply...