Urgent - call aspx function from ascx

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
LVL 9
Type25Asked:
Who is Participating?
 
ee_ai_constructCommented:
Question answered by asker or dialog deemed valuable.
Closed, 500 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0
 
RejojohnyCommented:
just asking .. should myfunction need to be public?
0
 
Type25Author Commented:
it is public
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Type25Author Commented:
intellisense actually likes the above code and suggests i can call it but it just won't compile
0
 
Type25Author Commented:
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
 
YZlatCommented:
put the function in a separate public module, then it will be accessible from every file of the application
0
 
b1xml2Commented:
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
 
ihenryCommented:
Isn't that with just

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

should be working?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.