Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
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 2:30am
Edited 7-Apr-11 5:38am
Prerak Patel at 7-Apr-11 7:31am
use pre tag for code block
SAKryukov at 7-Apr-11 7:51am
Sandeep Mewara at 7-Apr-11 10:38am
Did on his behalf!
SAKryukov at 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 at 7-Apr-11 13:16pm
It's Ok. Had no intention to point anything.
All in good spirit. :)
SAKryukov at 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
0 Sergey Alexandrovich Kryukov 8,478
1 OriginalGriff 6,516
2 Peter Leow 3,567
3 Zoltán Zörgő 3,386
4 Richard MacCutchan 2,397

Advertise | Privacy | Mobile
Web02 | 2.8.150123.1 | Last Updated 7 Apr 2011
Copyright © CodeProject, 1999-2015
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