Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 19, 2008 07:12 AM by niranjana
Member
6 Points
129 Posts
Jul 05, 2008 08:50 AM|LINK
I am using vb.net.
In my application am using one usercontrol.
i want to call a function from parent after clicking one button in user control
how can i achieve this?
thanks
niranajan
Contributor
4393 Points
687 Posts
Jul 05, 2008 09:49 AM|LINK
Hi Niranjana,
U can call the function using following way.
In Aspx page (ClassName: _ParentPage)
Public Function CallFromChildControl()
In Ascx page
DirectCast(Me.Page, _ParentPage).CallFromChildControl()
However, I will not recommend u to call such method. Rather u should create One Class and Shared function. Afterthen, u can call this function from both ascx page and aspx page.
I hope im clear enough.
Jul 05, 2008 10:11 AM|LINK
This is not working with my application
there if i use my parent class name it is showing error
Jul 05, 2008 10:20 AM|LINK
R u calling parent page function from UserControl's Button Click event? If yes then this should work.
If still ur getting error then plz post ur code.
Jul 05, 2008 07:26 PM|LINK
hi,
i will explaing my problem in detail.
I am using asp.net/vb.net.
In my appln. i have one aspx page and 2 user controls.like..below
MainForm --> Parent usercontrol --> child usercontrol
i want to call a method from of Parent usercontrol from my child usercontorl.
Here is my sample code for both parent and child user control
Parent.ascx
----------------
page load()
end
public sub getValues()
some code here
End sub
private sub attach()
UCChild.Read()
End Sub -> UCChild is my child user control
UCChild.ascx
------------------
public sub read()
-----------------------
---- -------------
call attach()
//Here some code
//After this i want to call getValues() from my parent child control
how it possible ?
Jul 06, 2008 05:00 AM|LINK
Ok niranjana,
I understood ur problem. U want to call the method of Child UserControl from Parent UserControl.
In such case u can use the following code.
In Parent.ascx (ClassName: _ParentControl, ChildControl InstanceName: UCChild)
Direcast(UCChild, _ChildControl).Read()
In Child.ascx (ClassName: _ChildControl)
I hope this will help u.
Jul 06, 2008 10:38 AM|LINK
thank you for giving me such valuable information.
but here i want to call method of my parent control from my child control. not in reverse.
Jul 07, 2008 03:52 AM|LINK
Oh, anyway then look at the following snippet
In Parent.ascx (ClassName: _ParentControl)
Public Sub Read() ' -- This is the function u want to call
DirectCast(Me.Parent, _ParentControl).Read()
Aug 19, 2008 06:58 AM|LINK
finally i got a method to achieve the same
we can use either of the following methods
1) Using delegates
2) Page.GetType().InvokeMember("checkvalues", Reflection.BindingFlags.InvokeMethod, Nothing, Me.Page, Nothing)
where 'checkvalues' is the parent method .
thanks for all for giving me the information
niranjana
Aug 19, 2008 07:12 AM|LINK
we can use either of the following to call a method of parent control from user contorl
1) Using delegate
2) Page.GetType().InvokeMember("getValues", Reflection.BindingFlags.InvokeMethod, Nothing, Me.Page, Nothing)
where getValues is the parent method
niranjana
Member
6 Points
129 Posts
How to call method of a parent from a child user control.
Jul 05, 2008 08:50 AM|LINK
I am using vb.net.
In my application am using one usercontrol.
i want to call a function from parent after clicking one button in user control
how can i achieve this?
thanks
niranajan
Coool
Contributor
4393 Points
687 Posts
Re: How to call method of a parent from a child user control.
Jul 05, 2008 09:49 AM|LINK
Hi Niranjana,
U can call the function using following way.
In Aspx page (ClassName: _ParentPage)
Public Function CallFromChildControl()
In Ascx page
DirectCast(Me.Page, _ParentPage).CallFromChildControl()
However, I will not recommend u to call such method. Rather u should create One Class and Shared function. Afterthen, u can call this function from both ascx page and aspx page.
I hope im clear enough.
Parth Patel
Software Engineer
niranjana
Member
6 Points
129 Posts
Re: How to call method of a parent from a child user control.
Jul 05, 2008 10:11 AM|LINK
This is not working with my application
there if i use my parent class name it is showing error
Coool
Contributor
4393 Points
687 Posts
Re: How to call method of a parent from a child user control.
Jul 05, 2008 10:20 AM|LINK
R u calling parent page function from UserControl's Button Click event? If yes then this should work.
If still ur getting error then plz post ur code.
Parth Patel
Software Engineer
niranjana
Member
6 Points
129 Posts
Re: How to call method of a parent from a child user control.
Jul 05, 2008 07:26 PM|LINK
hi,
i will explaing my problem in detail.
I am using asp.net/vb.net.
In my appln. i have one aspx page and 2 user controls.like..below
MainForm --> Parent usercontrol --> child usercontrol
i want to call a method from of Parent usercontrol from my child usercontorl.
Here is my sample code for both parent and child user control
Parent.ascx
----------------
page load()
end
public sub getValues()
some code here
End sub
private sub attach()
UCChild.Read()
End Sub -> UCChild is my child user control
UCChild.ascx
------------------
public sub read()
-----------------------
---- -------------
call attach()
End sub
private sub attach()
//Here some code
//After this i want to call getValues() from my parent child control
End sub
how it possible ?
End sub
Coool
Contributor
4393 Points
687 Posts
Re: How to call method of a parent from a child user control.
Jul 06, 2008 05:00 AM|LINK
Ok niranjana,
I understood ur problem. U want to call the method of Child UserControl from Parent UserControl.
In such case u can use the following code.
In Parent.ascx (ClassName: _ParentControl, ChildControl InstanceName: UCChild)
Direcast(UCChild, _ChildControl).Read()
In Child.ascx (ClassName: _ChildControl)
I hope this will help u.
Parth Patel
Software Engineer
niranjana
Member
6 Points
129 Posts
Re: How to call method of a parent from a child user control.
Jul 06, 2008 10:38 AM|LINK
thank you for giving me such valuable information.
but here i want to call method of my parent control from my child control. not in reverse.
Coool
Contributor
4393 Points
687 Posts
Re: How to call method of a parent from a child user control.
Jul 07, 2008 03:52 AM|LINK
Oh, anyway then look at the following snippet
In Parent.ascx (ClassName: _ParentControl)
Public Sub Read() ' -- This is the function u want to call
In Child.ascx (ClassName: _ChildControl)
DirectCast(Me.Parent, _ParentControl).Read()
Parth Patel
Software Engineer
niranjana
Member
6 Points
129 Posts
Re: How to call method of a parent from a child user control.
Aug 19, 2008 06:58 AM|LINK
finally i got a method to achieve the same
we can use either of the following methods
1) Using delegates
2) Page.GetType().InvokeMember("checkvalues", Reflection.BindingFlags.InvokeMethod, Nothing, Me.Page, Nothing)
where 'checkvalues' is the parent method .
thanks for all for giving me the information
niranjana
niranjana
Member
6 Points
129 Posts
Re: How to call method of a parent from a child user control.
Aug 19, 2008 07:12 AM|LINK
we can use either of the following to call a method of parent control from user contorl
1) Using delegate
2) Page.GetType().InvokeMember("getValues", Reflection.BindingFlags.InvokeMethod, Nothing, Me.Page, Nothing)
where getValues is the parent method
niranjana