473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Refreshing a user control

I have a page header that I made as a user control (ascx) that I drop on
every page in my application. The application is an eCommerce application
and I have a total for items in the cart on the header. To keep this total
in sync, I count the items in the cart and refresh the label text in the
load event of my header control. This all works well, except for one
scenario. When the user is on the "Show Cart" page, they can delete items
from the cart. I implemented this using the DeleteCommand of a datagrid.
When this is done, the total does not reflect the item being deleted until I
manually refresh the page.
So I'd like to be able to refresh the header control or even the whole page
if an item is deleted. How can I do that? Thanks!

Matt
Nov 18 '05 #1
6 1960
I'm guessing it's that the UserControl gets it's data, then the item is
deleted - but the usercontrol still has the predeleted information?

In this case, I recommend having a Refresh method on your UserControl that
can refresh the data, and have the code that deletes items call this method
to force the usercontrol to use the new data.

"MattB" <so********@yahoo.com> wrote in message
news:30*************@uni-berlin.de...
I have a page header that I made as a user control (ascx) that I drop on
every page in my application. The application is an eCommerce application
and I have a total for items in the cart on the header. To keep this total
in sync, I count the items in the cart and refresh the label text in the
load event of my header control. This all works well, except for one
scenario. When the user is on the "Show Cart" page, they can delete items
from the cart. I implemented this using the DeleteCommand of a datagrid.
When this is done, the total does not reflect the item being deleted until I manually refresh the page.
So I'd like to be able to refresh the header control or even the whole page if an item is deleted. How can I do that? Thanks!

Matt

Nov 18 '05 #2
Thanks. I haven't done this before - got any (or links to) examples?
Really the part I need to know is how do I refresh the control?
I was thinking there would be something like Page.Refresh, but I couldn;t
find such a thing.
Marina wrote:
I'm guessing it's that the UserControl gets it's data, then the item
is deleted - but the usercontrol still has the predeleted information?

In this case, I recommend having a Refresh method on your UserControl
that can refresh the data, and have the code that deletes items call
this method to force the usercontrol to use the new data.

"MattB" <so********@yahoo.com> wrote in message
news:30*************@uni-berlin.de...
I have a page header that I made as a user control (ascx) that I
drop on every page in my application. The application is an
eCommerce application and I have a total for items in the cart on
the header. To keep this total in sync, I count the items in the
cart and refresh the label text in the load event of my header
control. This all works well, except for one scenario. When the user
is on the "Show Cart" page, they can delete items from the cart. I
implemented this using the DeleteCommand of a datagrid. When this is
done, the total does not reflect the item being deleted until I
manually refresh the page.
So I'd like to be able to refresh the header control or even the
whole page if an item is deleted. How can I do that? Thanks!

Matt

Nov 18 '05 #3
Actually, it works if I just redirect to the same page I'm on (to refresh)
so I'm using that for now. Is there a betterway to do that or is the
redirect OK? Thanks!

Marina wrote:
I'm guessing it's that the UserControl gets it's data, then the item
is deleted - but the usercontrol still has the predeleted information?

In this case, I recommend having a Refresh method on your UserControl
that can refresh the data, and have the code that deletes items call
this method to force the usercontrol to use the new data.

"MattB" <so********@yahoo.com> wrote in message
news:30*************@uni-berlin.de...
I have a page header that I made as a user control (ascx) that I
drop on every page in my application. The application is an
eCommerce application and I have a total for items in the cart on
the header. To keep this total in sync, I count the items in the
cart and refresh the label text in the load event of my header
control. This all works well, except for one scenario. When the user
is on the "Show Cart" page, they can delete items from the cart. I
implemented this using the DeleteCommand of a datagrid. When this is
done, the total does not reflect the item being deleted until I
manually refresh the page.
So I'd like to be able to refresh the header control or even the
whole page if an item is deleted. How can I do that? Thanks!

Matt

Nov 18 '05 #4
I just described exactly what needs to be done. Write a method on the user
control (surely you've written methods before), and then just call it from
your page (I'm sure you've called methods on objects).

"MattB" <so********@yahoo.com> wrote in message
news:30*************@uni-berlin.de...
Thanks. I haven't done this before - got any (or links to) examples?
Really the part I need to know is how do I refresh the control?
I was thinking there would be something like Page.Refresh, but I couldn;t
find such a thing.
Marina wrote:
I'm guessing it's that the UserControl gets it's data, then the item
is deleted - but the usercontrol still has the predeleted information?

In this case, I recommend having a Refresh method on your UserControl
that can refresh the data, and have the code that deletes items call
this method to force the usercontrol to use the new data.

"MattB" <so********@yahoo.com> wrote in message
news:30*************@uni-berlin.de...
I have a page header that I made as a user control (ascx) that I
drop on every page in my application. The application is an
eCommerce application and I have a total for items in the cart on
the header. To keep this total in sync, I count the items in the
cart and refresh the label text in the load event of my header
control. This all works well, except for one scenario. When the user
is on the "Show Cart" page, they can delete items from the cart. I
implemented this using the DeleteCommand of a datagrid. When this is
done, the total does not reflect the item being deleted until I
manually refresh the page.
So I'd like to be able to refresh the header control or even the
whole page if an item is deleted. How can I do that? Thanks!

Matt


Nov 18 '05 #5
Hi.

Calling a public method of a UserControl that takes care of changing some
property of some control (label or something) is ok, but ugly and not
manageable. The normal and most elegant approach would be to use events. For
instance:

your page gets loaded;
grid (or other control on the page itself) gets bound to some data sourse;
UserControl gets loaded, too;
initially that label (or whatever) of UserControl gets its Text property set
to something;
user clicks Delete link or button on your grid;
DeleteCommand event (or whatever you have attached to this action) gets
fired;
you do your magic to get rid of that record and re-bind the grid;
in the same event handler (DeleteCommand of the grid) you fire your own
event that you declared inside of the page's class or outside;
you can declare your event parameters class inherited from EventArgs class
which will be "used" by your event and instantiate it with your own
properties when you fire your custom event;
your UserControl will subscribe to that page's event and will "listen" to it
(look inside of InitializeComponent() method that VS created in your page's
class - that's how it's done);
if it "hears" event, it gets the total records from your custom
EventArgs-based class or (ugly way) goes to db again and finds out that
total number again.

Sounds awfully complicated but in a real life it's just several lines of
code. That way your page lives completely separate life as well as your
UserControl; they don't care about each other unless that event gets fired.
That's how it should be done.

You can start reading more about events and how to work with them here:
http://www.codeproject.com/csharp/eventdelegates.asp or check MSDN and
framework documentation. It's a great stuff, soon you'll be wandering how
you've managed to live without them :)

Regards,
Kikoz
"MattB" <so********@yahoo.com> wrote in message
news:30*************@uni-berlin.de...
I have a page header that I made as a user control (ascx) that I drop on
every page in my application. The application is an eCommerce application
and I have a total for items in the cart on the header. To keep this total
in sync, I count the items in the cart and refresh the label text in the
load event of my header control. This all works well, except for one
scenario. When the user is on the "Show Cart" page, they can delete items
from the cart. I implemented this using the DeleteCommand of a datagrid.
When this is done, the total does not reflect the item being deleted until
I manually refresh the page.
So I'd like to be able to refresh the header control or even the whole
page if an item is deleted. How can I do that? Thanks!

Matt

Nov 18 '05 #6
MattB wrote:
Thanks. I haven't done this before - got any (or links to) examples?


You may find this article helpful in learning more about User Controls:

An Extensive Examination of User Controls
http://tinyurl.com/6p2ju

It contains examples of adding properties/methods to User Controls, as
well as events. hth

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Philo Del Middleston | last post by:
I've been searching, but apparently not phrasing my search right, so I'm going to float a question out here in the meantime... I'm wondering how to go about refreshing the content of a control...
1
by: LRD | last post by:
Form not refreshing after autopostback unless keyboard or mouse move Hi, We created several new ASP.NET C# forms for our intranet. In each form we use panels for different sections of the...
1
by: Microsoft | last post by:
I am having a problem where the gui is not refreshing. I have an ActiveX control that displays output from a ccd camera on the main gui. The control is embedded in a usercontrol. The usercontrol...
0
by: Do | last post by:
Hi, I have a datagrid in a custom user control that must be refreshed after I click a button. My custom user control is named dtgDocuments. I can't find any kind of reload method for the...
3
by: Aitham alama | last post by:
Hi There, My question is as following, I have a webform (Webform1) which contains one label control and command button, when the user clicks the button another webform (Webform2) appears,...
5
by: Jensen Bredal | last post by:
Hello, I need to display self refreshing information on a web page written with asp.net. I would image that the info would be displayed either as part of a user control or a web control. How can...
10
by: Nathan Sokalski | last post by:
One thing that I have often needed to do that I have been unable to find a way to do is refresh the page (basically do the same thing as pressing the browser's Refresh button). I know how to do...
9
by: Bali | last post by:
Default.aspx is the starting page containing a control(ascx) which has asp:button control on it. On the button click event it has to open a new page as a modal control. Since refreshing a page in a...
0
by: Bali | last post by:
Default.aspx is the starting page containing a control(ascx) which has asp:button control on it. On the button click event it has to open a new page as a modal control. Since refreshing a page in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.