SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question UserControl Problem

    Let there be an UserControl loaded in an .aspx page

    <&#37;@ Register Src="UserControl/UCDetail.ascx" TagName="UCDetail" TagPrefix="UCDetailUC" %>

    ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
    ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
    ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

    <UCDetailUC:UCDetail ID="usrCtlUCDetail" runat="server" Visible="false" >
    </UCdDetailUC:UCdDetail>

    In C# Page of another UserControl (say UcTest.ascx) it is written in a Button Click :

    UserControl UCDetail = null;
    UCDetail = (UserControl)Parent.FindControl("usrCtlUCDetail");


    Type ucType = UCdDetail.GetType();

    System.Reflection.PropertyInfo ucPageHeadingProperty = ucType.GetProperty("CID");
    ucPageHeadingProperty.SetValue(UCDetail, CId, null);
    UCDetail.Visible = true;
    Now I see that This sets the value of the property of the User Control CID; but it cannot load the UserControl again. So It cannot call the Method of that page. So I have a problem.

    I tried to use :
    System.Reflection.MethodInfo ucPageHeadingMethod = ucType.GetMethod("Page_Load", System.Reflection.BindingFlags.Public);
    ucPageHeadingMethod.Invoke(UCDetail, null);
    but it did not work.
    Can anyone provide me any suggestion ?
    Thanks

  2. #2
    SitePoint Addict
    Join Date
    Apr 2006
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hello !
    Any Help from anyone ?
    Last edited by sovan; Mar 16, 2009 at 03:36.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2009
    Location
    England
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can I re-phrase it, so that I can have a better understanding, and then workout what I've missed.

    1. User control A placed on page
    2. User control B placed on page, wishes to be a buddy control because it wishes to gain control, access properties of User Control A
    3. To achieve your aims, you call Page_Load manually, so that the page, has TWO page loads in its life cycle

    A) I'm confused why you ever thought step 3, would do anything other than make a mess ?
    B) If control B is after control A on the page, then yes it could be too late, you'll have to set the values in control A before its life cycle is started. But this all depends on which part of the life cycle of the control that needs setting.
    C) Maybe better is join Control A and Control B together, into some sort of super control, giving control over both life cycles together.
    D) Move the code that's setting values in Control A from, for example OnLoad() to OnPreRender(), so that control B has time to influence them.

    Life Cycle of page (As remember and not researched, so will be wrong)

    Page_PreInit()
    Page_Init()
    ControlA_Init()
    ControlB_Init()
    Page_InitComplete()
    Page_Load()
    ControlA_Load()
    ControlB_Load()
    Page_PreRender()
    ControlA_PreRender()
    ControlB_PreRender()
    Page_PreRenderComplete()
    Page_Render()
    ControlA_Render()
    ControlB_Render()
    Page_Unload()
    ControlA_Unload()
    ControlB_Unload()

    (I will have missed steps out, but the gist is there)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •