473,695 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1972
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********@yah oo.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********@yah oo.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********@yah oo.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********@yah oo.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********@yah oo.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 InitializeCompo nent() 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********@yah oo.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******@4guysf romrolla.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
5008
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 (say, a selector) without refreshing the page. For example, if I have these selects: Company: <pick a company> Contact: <pick a contact> When they pick the company, I'd like to refill the contact selector based on
1
392
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 form that are visible or not depending on what the user is doing. Each particular form.aspx page has a user control on it. This user control contains the form HTML and the C# code.
1
1632
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 has a public method that will allow a reference it itself to be passed back so that other classes can invoke methods and change properties on the AX control. This is important, since other classes may be responsible for doing things like...
0
1076
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 custom user control. What do I do to reload this control?
3
1840
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, webform2 contains only one control which is the Calendar control, I want to do the following 1- when the user selects a date from the webform2, I want the value
5
3478
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 this be done? The information will come from a database and the displaying should loop throug a table in the database. Many thank in advance JB
10
2184
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 this using Javascript/JScript, but I have situations in which I need it to be done immediately after code that is part of my other code. Is there any way to do this? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
9
4426
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 dialog box ended up opening up a new browser window with the aspx page, I read on a forum that I should use the iframe control and since I have to open a bunch of pages as diaogboxes, I created a general page(Container.aspx) which has an iframe...
0
2060
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 dialog box ended up opening up a new browser window with the aspx page, I read on a forum that I should use the iframe control and since I have to open a bunch of pages as diaogboxes, I created a general page(Container.aspx) which has an...
0
8617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8553
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9112
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8815
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7650
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6483
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5827
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.