dynamically writing property values to a control INSIDE of a user control?

Discussion in 'ASP .Net' started by Guest, Oct 1, 2006.

  1. Guest

    Guest Guest

    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 iself, 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
    Guest, Oct 1, 2006
    #1
    1. Advertising

  2. In page, you should either embed the value in the HTML tags (ASP.NET tags)
    or use Init (not Page Load) to set the value.

    In the control, you can be a bit more lax and do not have to aim for Init(),
    but it probably will not hurt you.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA
    http://gregorybeamer.spaces.live.com/

    *************************************************
    Think Outside the Box!
    *************************************************
    <> wrote in message
    news:...
    >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 iself, 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
    >
    >
    >
    Cowboy \(Gregory A. Beamer\), Oct 1, 2006
    #2
    1. Advertising

  3. Guest

    Guest Guest

    Ah, good, thank you so much. Writing Page_Init() method for the aspx page
    indeed solved the problem, like this:

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

    User controls seem so powerful in allowing you to build parameterized,
    generic , reusuable functionality. It's too bad these little gotchas trip up
    us newbies. I wonder if there's a way that the VS.NET IDE could cue you to
    the right practices: maybe you could help it figure out intent with xml
    markup or something.

    Anyway, thank you very much. Now to finish my abstracted
    uploading-and-image-resizing-and-cataloguing widget. ;)

    -KF

    "Cowboy (Gregory A. Beamer)" <> wrote in
    message news:%...
    > In page, you should either embed the value in the HTML tags (ASP.NET tags)
    > or use Init (not Page Load) to set the value.
    >
    > In the control, you can be a bit more lax and do not have to aim for
    > Init(), but it probably will not hurt you.
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    > http://gregorybeamer.spaces.live.com/
    >
    > *************************************************
    > Think Outside the Box!
    > *************************************************
    > <> wrote in message
    > news:...
    >>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 iself, 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
    >>
    >>
    >>

    >
    >
    Guest, Oct 1, 2006
    #3
    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. Korel Oktar
    Replies:
    0
    Views:
    1,928
    Korel Oktar
    Jan 21, 2008
  2. Bryan Holland

    Refer to a custom property of a dynamically loaded user control

    Bryan Holland, Nov 17, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    169
    Dave Rothgery
    Nov 17, 2003
  3. Dave

    Setting user control property dynamically?

    Dave, May 27, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    132
    Natty Gur
    May 28, 2004
  4. Roman
    Replies:
    2
    Views:
    246
    Roman
    Jan 4, 2005
  5. Kiran More
    Replies:
    2
    Views:
    304
    Kiran More
    Nov 14, 2006
Loading...

Share This Page