[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Urgent - call aspx function from ascx

Posted on 2005-04-15
9
Medium Priority
?
1,974 Views
Last Modified: 2011-10-03
Very urgent, for some reason i just can't get this working.

I have an aspx page with a function, let's call it  Function1

I also have a user control which sits on the main aspx page, how from the ascx page can i run my function on my aspx page?

Don't want to raise any events.

Just want to do something like

myaspxpage = (myaspxpage)this.parent.page;

myaspxpage.Function1();

But it just isn't happening, won't cast the page like that.

Any ideas?

Thanks
0
Comment
Question by:Type25
8 Comments
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13789393
just asking .. should myfunction need to be public?
0
 
LVL 9

Author Comment

by:Type25
ID: 13789412
it is public
0
 
LVL 9

Author Comment

by:Type25
ID: 13789414
intellisense actually likes the above code and suggests i can call it but it just won't compile
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:Type25
ID: 13789431
Ah ok... now it works..

CompleteReportPhotos pg = (CompleteReportPhotos)this.Parent.Page;
pg.returnItemCategories(-1,-1);

How strange. I think VS.NET got slightly confused between compliations.

0
 
LVL 35

Expert Comment

by:YZlat
ID: 13790330
put the function in a separate public module, then it will be accessible from every file of the application
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13791376
actually, if the UserControl is grabbing data from the Page, I would encourage using interfaces...
1. That way any other page that implements the interface can call the user contro1
or
2. when the page implements the interface, you can call the values from the page.

as in
public class MyPage : Page, IMyPage
{
 
      #region IMyPage implementation
      string IMyPage.CategoryId
      {
            get { return ViewState["CategoryId"] == null ? string.Empty : (string)ViewState["CategoryId"]; }
      }
      #endregion
}

public interface IMyPage
{
      string CategoryId { get; }
}

public class MyUserControl : UserControl
{
      protected Label Category;
      private IMyPage PageInterface
      {
            get { return this.Page; }
      }
      
      private void Page_Load(object sender,EventArgs e)
      {
            if (! this.IsPostBack)
            {
                  this.Category.Text = this.PageInterface.CategoryId;
            }
      }
      
      private void Page_Init(object sender,EventArgs e)
      {
            IMyPage _interface = this.Page as IMyPage;
            if (_interface == null)
                  throw new ApplicationException("Parent Page Must Implement The IMyPage Interface");
      }
      
}

That way, you are controlling from the page what data gets sent to where...a very elegant delivery pathway if i might say so...
0
 
LVL 20

Expert Comment

by:ihenry
ID: 13792263
Isn't that with just

myaspxpage = (myaspxpage)this.Page;
myaspxpage.Function1();

should be working?
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 13819790
Question answered by asker or dialog deemed valuable.
Closed, 500 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

831 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