Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Passing property values to controls embedded inside of user controls?

Back to Forum: Tech Off
  • User profile image
    kenfine

    I want to use codebehind to pass property values to a control that I've embedded INSIDE of a user control.
     
    In other words, let's say I have the following:
     
    MyPage.aspx
    ...with the following control placed on it...
        MyUserControl.ascx
    ... and inside of MyUserControl.ascx, is an instance of ....
                MyCommercialUploadControl1
     
    I want to be able to write a property to the embedded commerical component:
                MyCommercialUploadControl1.TargetFolder
     
    I want to be able write this property programmatically from the aspx page that originally called the instance of MyUserControl, as follows:
     
    [from MyPage.aspx]
            MyUserControl.TargetFolder = @"c:\whatever";
     
    Failure #1: I attempted to add logic to the codebehind for my .ascx that read the value of a property attached to itself, and then mapped that value to the embedded commercial control, e.g.
     
    MyCommercialUploadControl1.TargetFolder = this.TargetFolder
    // "this" refers to the ascx instance
     
    This did not work.
     
    Failure #2: I experimented with various scenarios involving doing the mappings onPreInit, thinking I might be running into a page lifecycle issue. This did not work either.
     
    I can successfully write properties to the user control itself, but I haven't figured out how to write properties to controls INSIDE of the control. In all cases the debugger indicates null values where I want my properties to end up. Can anyone help?
     
    Thank you.
    -KF
     

  • User profile image
    kenfine

    Answering my Q (with a little help from MSFT's friends):

    the programmatic assignments on the .aspx page need to be wrapped in the Page_Init() event, like so:

    protected void Page_Init()
    {
    PictureUploaderAndProcessor1.PathVirtual =
    "~/ni/apps/xxx/images/submitted/";
    }

    do that, and everything works like a charm.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.