Reload user control?

M

Mats Lycken

Hi,
I'm working on a webproject where I have several different user controls
loaded on a WebForm.
A problem arises when I in one webcontrol makes a change that should be
picked up by another user control.
For example a webshop. I have a datagrid of products in the shopping
cart in one user control. In another I have an overview of the shopping
cart (lists the products and a shows an order total).
When I remove a product from my datagrid I want the overview to reflect
the changes. The only solution I could think of was to do a
Server.Transfer() in the postback to "reload" the page, but it sounds to
me like a complete waste of resources to load the page twice for a
single postback.

Does anyone have any tips on how I could do it differently?

My shopping cart overview does not have an if(!IsPostBack) clause.

Thanks in advance
/Mats
 
G

Guest

You can dynamally load usercontrol by

UserControl userControl = this.LoadControl("virtualPath");

And put a PlaceHolder to hold the userControl

PlaceHolder.Controls.Add(userControl);

HTH

Elton Wang
 
M

Mats Lycken

Hi,
thanks for the reply.

The thing is that the other user control already has been added when the
other one has parsed its postback...
I use LoadControl() to load the usercontrols.
 
E

Elton Wang

What I mean is that each time you load usecontrol dynamically depending on
condition, even from begining.

HTH
 
S

Steven Cheng[MSFT]

Hi Mats,

IMO, you can consider customize your ascx usercontrol to expose some public
method which can be called by external users to update its UI
view(controls....). I think the shopping cart's change will cause a
postback, yes? If so, the postback event will be the proper time you find
the userControl's reference in the Page and then call that Usercontrol's
exposed public method( which will update the usercontrol's UI/Control
properties.....)....

Also, if you've ever had a look at the WSS or ASP.NET's web part controls
and its Connections part framework, this is just something like that, when
one control's status changes (cause postback), in the postback event, the
page will find another control that should react to the changes , and call
the corresponding method.......

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Date: Mon, 26 Dec 2005 19:22:48 +0100
| From: Mats Lycken <[email protected]>
| User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
| X-Accept-Language: en-us, en
| MIME-Version: 1.0
| Subject: Re: Reload user control?
| References: <[email protected]>
<[email protected]>
| In-Reply-To: <[email protected]>
| Content-Type: text/plain; charset=UTF-8; format=flowed
| Content-Transfer-Encoding: 7bit
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 1-1-3-42a.vs.vs.bostream.se 82.182.18.143
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:367079
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
| thanks for the reply.
|
| The thing is that the other user control already has been added when the
| other one has parsed its postback...
| I use LoadControl() to load the usercontrols.
|
| Elton W wrote:
| > You can dynamally load usercontrol by
| >
| > UserControl userControl = this.LoadControl("virtualPath");
| >
| > And put a PlaceHolder to hold the userControl
| >
| > PlaceHolder.Controls.Add(userControl);
| >
| > HTH
| >
| > Elton Wang
| >
| >
| > "Mats Lycken" wrote:
| >
| >
| >>Hi,
| >>I'm working on a webproject where I have several different user
controls
| >>loaded on a WebForm.
| >>A problem arises when I in one webcontrol makes a change that should be
| >>picked up by another user control.
| >>For example a webshop. I have a datagrid of products in the shopping
| >>cart in one user control. In another I have an overview of the shopping
| >>cart (lists the products and a shows an order total).
| >>When I remove a product from my datagrid I want the overview to reflect
| >>the changes. The only solution I could think of was to do a
| >>Server.Transfer() in the postback to "reload" the page, but it sounds
to
| >>me like a complete waste of resources to load the page twice for a
| >>single postback.
| >>
| >>Does anyone have any tips on how I could do it differently?
| >>
| >>My shopping cart overview does not have an if(!IsPostBack) clause.
| >>
| >>Thanks in advance
| >>/Mats
| >>
|
 
M

Mats Lycken

Thanks for the tip Steven, I'll look into it!
Hi Mats,

IMO, you can consider customize your ascx usercontrol to expose some public
method which can be called by external users to update its UI
view(controls....). I think the shopping cart's change will cause a
postback, yes? If so, the postback event will be the proper time you find
the userControl's reference in the Page and then call that Usercontrol's
exposed public method( which will update the usercontrol's UI/Control
properties.....)....

Also, if you've ever had a look at the WSS or ASP.NET's web part controls
and its Connections part framework, this is just something like that, when
one control's status changes (cause postback), in the postback event, the
page will find another control that should react to the changes , and call
the corresponding method.......

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Date: Mon, 26 Dec 2005 19:22:48 +0100
| From: Mats Lycken <[email protected]>
| User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
| X-Accept-Language: en-us, en
| MIME-Version: 1.0
| Subject: Re: Reload user control?
| References: <[email protected]>
<[email protected]>
| In-Reply-To: <[email protected]>
| Content-Type: text/plain; charset=UTF-8; format=flowed
| Content-Transfer-Encoding: 7bit
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 1-1-3-42a.vs.vs.bostream.se 82.182.18.143
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:367079
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
| thanks for the reply.
|
| The thing is that the other user control already has been added when the
| other one has parsed its postback...
| I use LoadControl() to load the usercontrols.
|
| Elton W wrote:
| > You can dynamally load usercontrol by
| >
| > UserControl userControl = this.LoadControl("virtualPath");
| >
| > And put a PlaceHolder to hold the userControl
| >
| > PlaceHolder.Controls.Add(userControl);
| >
| > HTH
| >
| > Elton Wang
| >
| >
| > "Mats Lycken" wrote:
| >
| >
| >>Hi,
| >>I'm working on a webproject where I have several different user
controls
| >>loaded on a WebForm.
| >>A problem arises when I in one webcontrol makes a change that should be
| >>picked up by another user control.
| >>For example a webshop. I have a datagrid of products in the shopping
| >>cart in one user control. In another I have an overview of the shopping
| >>cart (lists the products and a shows an order total).
| >>When I remove a product from my datagrid I want the overview to reflect
| >>the changes. The only solution I could think of was to do a
| >>Server.Transfer() in the postback to "reload" the page, but it sounds
to
| >>me like a complete waste of resources to load the page twice for a
| >>single postback.
| >>
| >>Does anyone have any tips on how I could do it differently?
| >>
| >>My shopping cart overview does not have an if(!IsPostBack) clause.
| >>
| >>Thanks in advance
| >>/Mats
| >>
|
 
M

Mats Lycken

Sorry, I'm still not sure what you mean

Elton said:
What I mean is that each time you load usecontrol dynamically depending on
condition, even from begining.

HTH
 
S

Steven Cheng[MSFT]

You're welcome Mats,

If there is any further problem, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| Date: Wed, 28 Dec 2005 19:00:32 +0100
| From: Mats Lycken <[email protected]>
| User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
| X-Accept-Language: en-us, en
| MIME-Version: 1.0
| Subject: Re: Reload user control?
| References: <[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| In-Reply-To: <[email protected]>
| Content-Type: text/plain; charset=ISO-8859-1; format=flowed
| Content-Transfer-Encoding: 7bit
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 1-1-3-42a.vs.vs.bostream.se 82.182.18.143
| Lines: 1
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:367355
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks for the tip Steven, I'll look into it!
|
| Steven Cheng[MSFT] wrote:
| > Hi Mats,
| >
| > IMO, you can consider customize your ascx usercontrol to expose some
public
| > method which can be called by external users to update its UI
| > view(controls....). I think the shopping cart's change will cause a
| > postback, yes? If so, the postback event will be the proper time you
find
| > the userControl's reference in the Page and then call that
Usercontrol's
| > exposed public method( which will update the usercontrol's UI/Control
| > properties.....)....
| >
| > Also, if you've ever had a look at the WSS or ASP.NET's web part
controls
| > and its Connections part framework, this is just something like that,
when
| > one control's status changes (cause postback), in the postback event,
the
| > page will find another control that should react to the changes , and
call
| > the corresponding method.......
| >
| > Regards,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| > --------------------
| > | Date: Mon, 26 Dec 2005 19:22:48 +0100
| > | From: Mats Lycken <[email protected]>
| > | User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
| > | X-Accept-Language: en-us, en
| > | MIME-Version: 1.0
| > | Subject: Re: Reload user control?
| > | References: <[email protected]>
| > <[email protected]>
| > | In-Reply-To: <[email protected]>
| > | Content-Type: text/plain; charset=UTF-8; format=flowed
| > | Content-Transfer-Encoding: 7bit
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 1-1-3-42a.vs.vs.bostream.se 82.182.18.143
| > | Lines: 1
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet:367079
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Hi,
| > | thanks for the reply.
| > |
| > | The thing is that the other user control already has been added when
the
| > | other one has parsed its postback...
| > | I use LoadControl() to load the usercontrols.
| > |
| > | Elton W wrote:
| > | > You can dynamally load usercontrol by
| > | >
| > | > UserControl userControl = this.LoadControl("virtualPath");
| > | >
| > | > And put a PlaceHolder to hold the userControl
| > | >
| > | > PlaceHolder.Controls.Add(userControl);
| > | >
| > | > HTH
| > | >
| > | > Elton Wang
| > | >
| > | >
| > | > "Mats Lycken" wrote:
| > | >
| > | >
| > | >>Hi,
| > | >>I'm working on a webproject where I have several different user
| > controls
| > | >>loaded on a WebForm.
| > | >>A problem arises when I in one webcontrol makes a change that
should be
| > | >>picked up by another user control.
| > | >>For example a webshop. I have a datagrid of products in the
shopping
| > | >>cart in one user control. In another I have an overview of the
shopping
| > | >>cart (lists the products and a shows an order total).
| > | >>When I remove a product from my datagrid I want the overview to
reflect
| > | >>the changes. The only solution I could think of was to do a
| > | >>Server.Transfer() in the postback to "reload" the page, but it
sounds
| > to
| > | >>me like a complete waste of resources to load the page twice for a
| > | >>single postback.
| > | >>
| > | >>Does anyone have any tips on how I could do it differently?
| > | >>
| > | >>My shopping cart overview does not have an if(!IsPostBack) clause.
| > | >>
| > | >>Thanks in advance
| > | >>/Mats
| > | >>
| > |
| >
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top