Solved

how to call aspx page methods in ascx page

Posted on 2008-10-10
4
1,818 Views
Last Modified: 2013-11-07
Hi,
        I have a method  Sub PopulateCMDropDowns() in cmsearch.aspx page. i want to call that method in .ascx page(user control) method? could any one show me how to that?
method in ASPX page is 
Sub PopulateCMDropDowns()
 
method in .ascx page is 
 
Protected Sub DiagramDropDownList_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DiagramDropDownList.DataBound
 
        Dim strLastDiagramChoice As String
        Dim itmDropdownItem As ListItem
 
 
        < some code is here>
 
        If MyContext.ReportID = "CustomMetadata" Then 
            
           =========== here i want to call the Sub PopulateCMDropDowns()  method  =========
        Else
           
          Exit Sub
 
        End If
 
    End Sub

Open in new window

0
Comment
Question by:prasadpbr
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Richard Lee
ID: 22686542
Each control has a Page property. You need to cast this property to the specific page class you want. If you want the current page methods (the ones you have added) then cast to the name of your page class.
0
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 200 total points
ID: 22686543
Using delegate.

You can search for how to use delegate for more advance view.

Let say, in your ascx out side of the class you declare:
public delegate void PopulateCMDropDowns();
public partial class Controls_MyControl
{
           public event PopulateCMDropDowns evt_Populate;
           ...
          Protected Sub DiagramDropDownList_DataB......
                If MyContext.ReportID = "CustomMetadata" Then
           
           =========== here i want to call the Sub PopulateCMDropDowns()
              evt_Populate();
                 Else

}

in your aspx file, when you render or add this control (ucMyControl) to your page,  define the event for that control by:
ucMyControl.evt_Populate += PopulateCMDropDowns(PopulateCMDropDowns)

intelligense will help you to fullfil, it should be easy.

Hope this helps

JINN



0
 

Author Comment

by:prasadpbr
ID: 22686987
Hi,
   Jinn thanks for your reply. I did what you told But im getting error in .aspx page.


ucDiagramChoice.evt_Populate += PopulateCMDropDowns(PopulateCMDropDowns)

in this line im getting error like declaration expected.( ucDiagramChoice)
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22687194
Sorry   mybad I forgot the new word.
it should be:

ucDiagramChoice.evt_Populate += new PopulateCMDropDowns(PopulateCMDropDowns);

You can understand delegate is like a function pointer. It is every useful in your case (I use it a lot), the declaration of the delegate must have the same return type and parameters type of the invoke function.

Tell me if this works, you might wanna play around that in order to make the delegate work. And trust me: this is the right direction. Cause we have ton of similar cases.

JINN


0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 37
Vb.net threads keep increasing 2 49
VB.net Open video relating to control 2 29
Retrieve Active Directory Groups a User belongs to in VB.NET 3 43
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question