Solved

how to call aspx page methods in ascx page

Posted on 2008-10-10
4
1,811 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now