Click here to Skip to main content
13,089,943 members (42,084 online)
Rate this:
Please Sign up or sign in to 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 7-Apr-11 1:30am
Updated 7-Apr-11 4:38am
Prerak Patel 7-Apr-11 7:31am
use pre tag for code block
SAKryukov 7-Apr-11 7:51am
Sandeep Mewara 7-Apr-11 10:38am
Did on his behalf!
SAKryukov 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.
Sandeep Mewara 7-Apr-11 13:16pm
It's Ok. Had no intention to point anything.

All in good spirit. :)
SAKryukov 7-Apr-11 15:41pm
Sure. Thank you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

ShoppingCartControl shoppingCartControl = new ShoppingCartControl();

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 7 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100