Access custom page methods from a user control c#

Discussion in 'ASP .Net Web Controls' started by ultplyr, Aug 13, 2003.

  1. ultplyr

    ultplyr Guest

    From within my user control I need to access a method of the page that
    hosts the user control. I can do this by casting the page to the page
    that I need, but I don't know this at runtime.

    example:
    from within my control :
    myDatagrid.DataSource = ((vieworders.aspx)Page).PageMethod();

    is there a way to do this without casting.
    ie:
    dgrdToPage.DataSource = Page.PageMethod();

    thanks.
    ultplyr, Aug 13, 2003
    #1
    1. Advertising

  2. ultplyr

    ultplyr Guest

    Figured out a way to access a page's methods from a user control
    placed on that page. Hope this helps someone, it baffled me for
    awhile.

    From within the ASP.NET application namspace create an interface an
    place it in the code behind section of the .aspx page.
    Then implement that method in the code behind page class.

    namespace MyWebsite
    {
    public interface IData
    {
    DataView GetDataView();
    }

    public class My_ASPX_Page : System.Web.UI.Page
    {

    public DataView GetDataView()
    {
    DataView dvwMyDataView = new DataView();
    return dvwMyDataView;
    }
    }
    }


    In the code behind of the control class (.ascx) write the following
    code.

    public class Pager : System.Web.UI.UserControl
    {
    IData pgData;

    private void Page_Load(object sender, System.EventArgs e)
    {

    (IData) pgData = (IData) this.Page;
    MyDataGrid.DataSource = pgData.GetDataView();
    }
    }



    (ultplyr) wrote in message news:<>...
    > From within my user control I need to access a method of the page that
    > hosts the user control. I can do this by casting the page to the page
    > that I need, but I don't know this at runtime.
    >
    > example:
    > from within my control :
    > myDatagrid.DataSource = ((vieworders.aspx)Page).PageMethod();
    >
    > is there a way to do this without casting.
    > ie:
    > dgrdToPage.DataSource = Page.PageMethod();
    >
    > thanks.
    ultplyr, Aug 14, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leeor Chernov
    Replies:
    2
    Views:
    788
    Leeor Chernov
    Oct 16, 2005
  2. =?Utf-8?B?Q29uZ2Vybw==?=

    Access Methods on Page from user control

    =?Utf-8?B?Q29uZ2Vybw==?=, May 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,136
    Karl Seguin [MVP]
    May 16, 2006
  3. Chris Zopers

    Access user control from other user control

    Chris Zopers, Feb 20, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    570
    Nanda Lella[MSFT]
    Apr 27, 2009
  4. Matt Sokol
    Replies:
    2
    Views:
    375
    Theo Tillotson
    Aug 7, 2003
  5. Kenneth McDonald
    Replies:
    5
    Views:
    312
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page