Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to call a method named AddProductToCart() from ShoppingCartControl.ascx.cs file(user control) in Default.aspx.cs file..In Default.aspx.cs,I have the code:

using System;
using System.Web.UI;
public partial class _Default : Page
{

    protected void ProductControl_AddToCartClick(object sender, EventArgs e)
    {
        ProductControl product = (ProductControl)sender;
}}

where (Productcontrol) is a class in another .ascx.cs file.
This method is present in the ShoppingCartControl class which is in ShoppingCartControl.ascx.cs file.

How to call this method in aspx.cs file ? plz suggest
Reply will be highly appreciable !!!!!
Posted
Updated 7-Apr-11 4:38am
v3
Comments
Prerak Patel 7-Apr-11 7:31am    
use pre tag for code block
Sergey Alexandrovich Kryukov 7-Apr-11 7:51am    
Tag ASP.NET!
--SA
Sandeep Mewara 7-Apr-11 10:38am    
Did on his behalf!
Sergey Alexandrovich Kryukov 7-Apr-11 13:04pm    
Thank you Sandeep. I just wanted to get some sleep at that time. Not tagging important items if very distracting for all readers.
--SA
Sandeep Mewara 7-Apr-11 13:16pm    
It's Ok. Had no intention to point anything.

All in good spirit. :)

You can do it one of two ways:

0) Create a BasePage class that holds common methods that more than one page will need to access

1) Create a static class that holds methods that all code can access on the site. If these methods require access to page-specific variables, you'll have to set those variables as session variables or pass them as parameters to the static methods.
 
Share this answer
 
ShoppingCartControl shoppingCartControl = new ShoppingCartControl();
shoppingCartControl.AddProductToCart();


Or use any exixting instance of the object if available and applicable. The method should be a public or internal method based on the needs.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900