Click here to Skip to main content
14,331,865 members

Access Parent Control's Method from a Child Control

Rate this:
4.06 (13 votes)
Please Sign up or sign in to vote.
4.06 (13 votes)
20 Nov 2008CPOL
Simple technique to access parent page and controls method from a child control


This article is for the beginner level audience who has just started working on user controls. Sometimes while using user controls, you may need to access methods declared either on the parent user control and parent page from the child user control. Here is a simple solution for that.


I came across the same issue where I needed to access the method declared on the parent user control from the child user control and ended up searching for options. I got a simple solution using abstract classes as it was not possible to access the user defined methods in the Parent object.

Here is the little trick. I have created  abstract class AbstractUserControl and AbstractPage, where AbstractUserControl is inherited from System.web.UI.UserControl and AbstractPage is inherited from System.Web.UI.Page. I placed these two classes inside the App_code folder so that it will be accessible anywhere in the site.

Using the Code

Here is the abstract class with the declaration of abstract methods. These abstract methods will be overridden in the Page or UserControl where they need to be called from the child.

namespace CodeProject.Sample
public abstract class AbstractPage : System.Web.UI.Page 
public AbstractPage()
// TODO: Add constructor logic here

// implementation in the concrete class
public abstract void callMefromChild();

I added a similar abstract class for a user control to inherit.

Next, I use these abstract classes to achieve the functionality. Now it is pretty straight forward to access the parent page method from the child control. Here is the snippet:

protected void btnClick_Onclick(Object sender, EventArgs e)

Simple type casting of Parent.Page to the AbstractPage classes exposes the user defined method in the Page. We can use the same trick for accessing the method declared on the parent user control from the child user control.

I am a long time user of The Code Project and never contributed to the community. Today I am starting with this simple article and expecting to come up with some interesting stuff later on. Hope this helps somebody. Please free to post a comment if you need any clarifications.


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


About the Author

Moorthi N
Software Developer
United States United States
No Biography provided

Comments and Discussions

QuestionNice Article - Comments Pin
Member 1116663220-Oct-14 1:32
memberMember 1116663220-Oct-14 1:32 
GeneralExcellent artical Pin
denii15-Sep-09 23:45
memberdenii15-Sep-09 23:45 
GeneralMy vote of 2 Pin
Joe Sonderegger25-Nov-08 3:27
memberJoe Sonderegger25-Nov-08 3:27 
GeneralGood Job! Pin
ArielR24-Nov-08 23:13
memberArielR24-Nov-08 23:13 
GeneralDifferent approach Pin
guohuang22-Nov-08 7:32
memberguohuang22-Nov-08 7:32 
Generaldifficult Pin
Emiliana8512-Aug-08 16:43
memberEmiliana8512-Aug-08 16:43 
GeneralGood article. Pin
Rajib Ahmed9-Jul-08 5:26
memberRajib Ahmed9-Jul-08 5:26 
GeneralRe: Good article. Pin
Moorthi N9-Jul-08 11:05
memberMoorthi N9-Jul-08 11:05 
QuestionWhy cast ? Pin
Christian Graus9-Jul-08 4:23
protectorChristian Graus9-Jul-08 4:23 
AnswerRe: Why cast ? Pin
Moorthi N9-Jul-08 11:17
memberMoorthi N9-Jul-08 11:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 9 Jul 2008

Tagged as


20 bookmarked