Control referencing

G

Guest

How do i reference a control in the following scenario?

Master page has an ascx file which show the total items and value in a
shopping cart (using Profile data)

This needs to be updated when the cart is changed / amended.

The file structure =

master1.master with cartTotal.ascx with a label - lblTotal

shoppingCart.aspx with cart.ascx with events - CartGrid_RowUpdating etc

What i need to do is when the CartGrid_RowUpdating event fires i'd like to
reference the lblTotal in the cartTotal.ascx/ master1.master file and update
its contents.

Any suggestions?
 
A

Aidy

This is how I've done it, wouldn't mind other people's input so I'm sure I'm
missing a simple trick somewhere, it shouldn't be this complicated.

Create a class in your App_Code directory called IMyInterface and have this
in it

public interface IMyInterface

{

void MyMethod (int myParam)

}


Now have your shopping cat control implement this;

public partial class cartTotal: System.Web.UI.UserControl, IMyInterface

And implement the MyMethod

void IMyInterface .MyMethod (int myParam)

{

// Update your control here

}

Then in your shoppingCart page;

IMyInterface myInterface = (IMyInterface ) Master.FindControl("cartTotal1");

myInterface.MyMethod (123);
 
G

Guest

Thanks Aidy

Do you have a vb example?

Aidy said:
This is how I've done it, wouldn't mind other people's input so I'm sure I'm
missing a simple trick somewhere, it shouldn't be this complicated.

Create a class in your App_Code directory called IMyInterface and have this
in it

public interface IMyInterface

{

void MyMethod (int myParam)

}


Now have your shopping cat control implement this;

public partial class cartTotal: System.Web.UI.UserControl, IMyInterface

And implement the MyMethod

void IMyInterface .MyMethod (int myParam)

{

// Update your control here

}

Then in your shoppingCart page;

IMyInterface myInterface = (IMyInterface ) Master.FindControl("cartTotal1");

myInterface.MyMethod (123);
 
A

Aidy

Do you have a vb example?

No :) There is a c# to vb converted out there or maybe someone else can
help.
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top