want to call one c#.net function in one user control from another user control


hi
i have two user controls
info.ascx and personal.ascx
i have a function like
in info.ascx i have a function like showdetails()
{
ย 
}
now i want to access this function from personal.ascx
can i do this ?
thanks in advance.
shweta

Thanks

shweta

In a day when don't come across any problem -you can be sure that you are traveling in wrong path
0
shweta
7/2/2008 7:15:45 AM
๐Ÿ“ asp.net.web-forms
๐Ÿ“ƒ 93655 articles.
โญ 6 followers.

๐Ÿ’ฌ 4 Replies
๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ 2235 Views



ย you should better create a class where you will define the "functions" that you need in both files.
ย declare "static" the function and call it like nameofclass.nameoffunction
0
GillouX
7/2/2008 8:40:08 AM

In a web project you can't reference a Page or User control class from a stand-alone class.
If you want to reference the User Control class, you need to create a web application project.
ย 
See the comparison of both project types - http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx#wapp_topic5

-----------------
Rajeesh
My Blog
0
cvrajeesh
7/2/2008 8:47:14 AM

Assuming showdetails() is a public non-static method in info.ascx, you can only call it using an instance of the info.ascx User Control.
Therefore, in order to be able to call info.ascx's showdetails() in a response to an event in personal.ascx, you'd have to do it in the code behind of a page which contains instances of both of these User Controls. If you would like to do it consistently over several pages, I would recommend either you add an instance of info.ascx inside personal.ascx, or better yet build a 3rd User Control which contains both of them and place it in the relevant pages.
If any further clarifications are needed, please let me know.
Cheers.

Avi
0
avi
7/2/2008 8:49:15 AM

Hi shweta,
Yes it is possible to call function of one ascx control from another.
Suppose u have one page in which u have dropped 2 ascx control.
1. a.ascx - Control Id in Pageย : a1 - Class Name : _a
2. b.ascx - Control Id in Page : b1 - Class Name : _b
In a.ascx
Public Sub CallFromOutside()
End Sub
In b.ascx
DirectCast(Me.Parent.FindControl("a1"), _a).CallFromOutside()

Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
Ahmedabad
0
Coool
7/2/2008 9:26:30 AM
Reply: