Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to call aspx page methods in ascx page

Posted on 2008-10-10
4
Medium Priority
?
1,839 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 600 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 to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

972 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