Custom Control: Calling a function on calling page FROM a custom control ? help !!

I have a custom control placed on many pages, to make things simple, basically what I want to do is Call a function on the calling page from the custom control ie

Anyone have any ideas, simple solution would be good !! 


This is the code I have



Public Partial Class myControl
    Inherits System.Web.UI.UserControl

    Protected Sub testButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles testButton.Click
        'call save function on PersonalDetails.aspx.vb
    End Sub
End Class




Public Class PersonalDetails
    Inherits BasePage

    Public Function save() As Boolean
        '' do something
    End Function


Need to do the Simplest way possible 



8/30/2007 2:13:08 PM 3498 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 43

Hi DottyWelsh,

If the function you want to call is part of the System.Web.UI.Page, then you can call the method by accessing the Page property of the control:


but if you want to support custom code, then define a public interface in your custom control library like the following example:

public interface IPageWorker {
  object DoSomething(object parameter);

So, then the page should implement the interface and define the method’s body, while you can check in your control that the page implements the interface, in which case, – invoke the method:

IPageWorker pw = this.Page as IPageWorker;
if(p != null) {
  object value = pw.DoSomething(...);

Hope this helps…

8/30/2007 3:32:30 PM

thanks for that, can u expand a little.


I have created many interface classes and dont have a problem with that.


Im just a little unsure to how on the custom control i use it to call the function on the current page.

8/31/2007 8:14:38 AM

An interface in this case is used just as a marker which states that "the page on which the control is placed supports custom method functionality for your control". It's just like the way that IDisposable identifies an object which holds valuable resources which should be released by calling Dispose()

8/31/2007 4:36:12 PM

Similar Artilces:

Custom controls called from inside other custom controls???
I'm fairly new to writing controls in ASP.NET so, forgive the I am trying to create a base page class which will call 3 custom controls. This base page class will span across multiple projects hence the reason I am not creating user controls. These 3 custom controls are: 1. TopNav-uses render method to display an HTML table with graphics for top navigation. 2. ImagePairs-uses prerender method to add javascript code to manage what graphic is displayed in TopNav onMouseOver and onMouseOut 3. MgrHeader-uses render method to display an HTML table with s...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer sites and/or SharePoint sites why don't you just create Web Par...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

Web Custom Controls
Hi. I created 4 web custom controls (dropdown lists). I need to get back to the calling control (web page) where I am using these controls. I want to use the controls separately or use them as a type of hierarchy. When they are used individually (one per page), the dropdown list must be populated with all the items in the table. When used as a hierarchy (more than one per page), the one must be dependant on the other, and items from the table must be returned depending on what the user selected in the parent control (dropdown list). Is this even possible? Thanks yes, it is possible. In you...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

Creating Custom Controls With Custom Controls Inside Of Them
Hello, I am trying to create a custom control for creating tabs. The idea is that our designer can just use the control tags to generate the tabs.  The problem that I am running into is that I want to be able to have a custom control that allows any number of child custom controls. So there would be a TabContainer Control, and within that there would be any number of tabs.  The idea is similar to how an asp:DropDown list can have any number of ListItems within them.  Here is my code, any help is appreciated. 1 <!-- TAB CONTAINER -->2 <%@ Control Language=&...

Web Custom Control
Hi. I created 4 drop downlist controls as web custom controls, which I would either like to use seperately, or working together like a hierarchy (dependant on each other). The problem is, I need to communicate with the calling control (the web page where I dragged these controls on). When the dropdownlists are used seperately, they should return all items on a table, but when they are used together, the child dropdownlist should only return items from the table based on the selection of the parent dropdownlist just above it. Can anyone please help? Thanks. You should post this in the Build...

How can one call a custom server control DLL like a custom class library DLL
All -- How can one call a custom server control DLL like a custom class library DLL? Please help. I think that I am missing something simple? Or, maybe I am trying to do something impossible? Or, maybe something else? I have a custom server control DLL that I built, with a UI, etc, called... (A). App_Web_teamthemeselectorwebcontrol.ascx.cdcab7d2.dll ...and it works fine. I register my custom server control DLL on an ASPX page like this... (B). <%@ register tagprefix="team" namespace="Team.WebControls" assembly="App_Web_teamthemeselectorwebcontrol.a...

How to switch the visibility of a custom control while still get all the Javascript functionality included with that custom control?
Hello All, I have a custom DatePicker control which works well in the past non-AJAX aspx pages, and it also works in UpdatePanel as long as the initial Visible Property is set to true. But I need to set the initial Visibility to False, make it visible if user want to input a date (such as From XX Date To XX Date in a query ), and make it invisible if the user decide not to enter a date. It looks like the javascript used by the DatePicker control won’t be loaded if the initial Visible Property is set to False.  Here is the scenario: 1. Put a custom DatePicker...

Custom User Controls v. Custom Web Controls
Hi! Is it better for me to begin coding my controls instead of just designing them? What would the benefits be? I meen, i seem to be able to get all i need from just putting stuff together on an ASCX file but i'm obviously missing a huge concept here... please explain! Hi, creating user controls is indeed easier than creating custom server controls because you can simply drag & drop other controls on the form, easily add events to it, ... Custom controls however are better when you want to reuse them in several other projects. I like to create custom controls for small, reusable com...

Web resources about - Custom Control: Calling a function on calling page FROM a custom control ? help !! -

Resources last updated: 12/6/2015 12:33:42 AM