Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
I created a page and a usercontrol in asp.net,
I have two different data binding method in each page,
my codes are:

index.aspx.cs
public partial class index : System.Web.UI.Page
    {
     public void binding()
        {
         //database binding code
        }
    }

and

cart.ascx.cs
public partial class cart : System.Web.UI.UserControl
    {
        public void binding()
        {
         //database binding code
        }
    }


how can I use usercontrol's binding() into the page's binding()?

thank you

What I have tried:

I tried googling but I don't know anything ....
Posted
Updated 28-Jan-19 20:39pm
v2

Create a class with the shared code in it and call the code in that class from both controls. You might need to pass the controls you want to update as parameters to the methods in the shared class, it depends what kind of code you want to run.
 
Share this answer
 
v2
Comments
Farshad Razaghi 24-Jan-19 9:32am    
when I update database connected to Index.aspx,
the values of cart.ascx doesnt changed.
when you are adding reference of user control into page.you will get name of usercontrol.

so you have to use usercontrolname.MethodName();
eg:->cart.binding() in your page.

but the binding method should be public in usercontrol.
 
Share this answer
 
v2

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