Click here to Skip to main content
Rate this: bad
good
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 1:30am
Edited 7-Apr-11 4:38am
v3
Comments
Prerak Patel at 7-Apr-11 7:31am
   
use pre tag for code block
SAKryukov at 7-Apr-11 7:51am
   
Tag ASP.NET!
--SA
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.
--SA
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.
--SA
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 7 Apr 2011
Copyright © CodeProject, 1999-2014
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