Solved

how to call aspx page methods in ascx page

Posted on 2008-10-10
4
1,826 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

615 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