Kerala Microsoft Users Group

Windows 7 Deployability

Load page in runtime & access controls in that page

Latest post 06-29-2009 8:31 AM by roshanpm. 5 replies.
  • 06-28-2009 5:03 AM

    Load page in runtime & access controls in that page

    Hi -

    I want to list all the controls of a page(user input) from a webpages. Both the pages are a part of same web application.

    I tried below method, but it is failed. Please help

     

     

    object runTimePage = BuildManager.CreateInstanceFromVirtualPath(PATH, typeof(Page));

    Eventhough it is creting an object of the page, none of the controls are not loaded in to this object. How can I load all child controls in it.

    Thanks

    Roshan

     

    • Post Points: 25
  • 06-28-2009 10:08 PM In reply to

    Re: Load page in runtime & access controls in that page

    Roshan can you explain more? You want to load the Page to where? or you want a User control? 

    Thanks

    Anuraj P
    http://www.dotnetthoughts.net

    THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS.
    BEWARE OF BUGS IN THE ABOVE CODE; I HAVE ONLY PROVED IT CORRECT, NOT TRIED IT.

    • Post Points: 25
  • 06-29-2009 12:03 AM In reply to

    Re: Load page in runtime & access controls in that page

    Arun -

    I don't want to display the page as it is to the client. But I want to list all controls in a page. For eg. If user entered "Default.aspx" in a text box and press a button, I want to list name of all the controls in  "Default.aspx" in a datalist. Hope it is clear now.

    Thanks

    Roshan

    • Post Points: 25
  • 06-29-2009 3:18 AM In reply to

    Re: Load page in runtime & access controls in that page

    Any chance you are looking for a similar thing like this?  I hope no...

                foreach (Control ctrl in form1.Controls)
                {
                    Response.Write("Control Type: " + ctrl.GetType() +", Name:" + ctrl.ID  + "<br>");   
                }

    PraVeeN
    Microsoft MVP
    blog.ninethsense.com | kidoos.net

    • Post Points: 45
  • 06-29-2009 4:38 AM In reply to

    Re: Load page in runtime & access controls in that page

    I think yes,And I will use some recursive functions

    DataTable dataTable = new DataTable();

    dataTable.columns.Add("ControlId");
    dataTable.columns.Add("ControlName");

    function GetControls(control MyCtrl)
    {
    foreach(ctrl as control in MyCtrl.Controls))
    {
    Datarow dr = dataTable.NewRow
    if(ctrl.Controls.Count >= 1)
    {
     GetControls(Ctrl); 
    }
    dr["ControlId"] = ctrl.Id;
    dr["ControlName"] = ctrl.Name;
    dataTable.Rows.Add(dr);
    }

    Try this code

    Thanks

    Anuraj P
    http://www.dotnetthoughts.net

    THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS.
    BEWARE OF BUGS IN THE ABOVE CODE; I HAVE ONLY PROVED IT CORRECT, NOT TRIED IT.

    • Post Points: 5
  • 06-29-2009 8:31 AM In reply to

    Re: Load page in runtime & access controls in that page

    No Praveen, my issue is in getting controls from a Page object, which we created at runtime.

    Thanks

    Roshan

    • Post Points: 5
Page 1 of 1 (6 items) | RSS