Solved

how to call aspx page methods in ascx page

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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