How Can I Reference Custom Controls in the CreateUserWizard?

Discussion in 'ASP .Net Security' started by EagleRed@HighFlyingBirds.com, Feb 1, 2006.

  1. Guest

    I am creating a customized CreateUserWizard that has two steps. In the first
    step I add controls to collect the user's name and address. In the second
    step I collect information about the user's company, including the company
    address. I include a checkbox to allow use of the user's address as the
    company address.

    Both steps contain a dropdownlist for selecting the state. In the
    SelectedIndexChanged event handler on the first page I'd like to determine
    the state of the checkbox on the second step and also reference the
    dropdownlist on the second step and set the selection there. I would also
    like to copy the contents of the user address textboxes to the company
    textboxes in the "Next" button event handler.

    My problem is that I don't know how to reference these additional controls.
    I can see the standard controls included in the base template but not the
    controls I add.

    Any ideas or guidance would be greatly appreciated.
    , Feb 1, 2006
    #1
    1. Advertising

  2. Hi,

    yeah - controls inside of a template are not placed as a page field.

    This can be tricky - i am not sure how the CreateUserWizard handles this
    (have to look) - but the general way is:

    What i usually do is, enable page tracing in the page directive - and use
    the FindControl method of the parent control.

    ---------------------------------------
    Dominick Baier - DevelopMentor
    http://www.leastprivilege.com

    > I am creating a customized CreateUserWizard that has two steps. In
    > the first step I add controls to collect the user's name and address.
    > In the second step I collect information about the user's company,
    > including the company address. I include a checkbox to allow use of
    > the user's address as the company address.
    >
    > Both steps contain a dropdownlist for selecting the state. In the
    > SelectedIndexChanged event handler on the first page I'd like to
    > determine the state of the checkbox on the second step and also
    > reference the dropdownlist on the second step and set the selection
    > there. I would also like to copy the contents of the user address
    > textboxes to the company textboxes in the "Next" button event handler.
    >
    > My problem is that I don't know how to reference these additional
    > controls. I can see the standard controls included in the base
    > template but not the controls I add.
    >
    > Any ideas or guidance would be greatly appreciated.
    >
    Dominick Baier [DevelopMentor], Feb 1, 2006
    #2
    1. Advertising

  3. Guest

    Thanks. I have been doing some additional searching. One post has a
    suggestion like this:

    DropDownList listVariable = (DropDownList)
    CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("MyControlID");

    I tried this but the listVariable was null. It seems the custom controls
    that I add disappear into the mist.

    "Dominick Baier [DevelopMentor]" wrote:

    > Hi,
    >
    > yeah - controls inside of a template are not placed as a page field.
    >
    > This can be tricky - i am not sure how the CreateUserWizard handles this
    > (have to look) - but the general way is:
    >
    > What i usually do is, enable page tracing in the page directive - and use
    > the FindControl method of the parent control.
    >
    > ---------------------------------------
    > Dominick Baier - DevelopMentor
    > http://www.leastprivilege.com
    >
    > > I am creating a customized CreateUserWizard that has two steps. In
    > > the first step I add controls to collect the user's name and address.
    > > In the second step I collect information about the user's company,
    > > including the company address. I include a checkbox to allow use of
    > > the user's address as the company address.
    > >
    > > Both steps contain a dropdownlist for selecting the state. In the
    > > SelectedIndexChanged event handler on the first page I'd like to
    > > determine the state of the checkbox on the second step and also
    > > reference the dropdownlist on the second step and set the selection
    > > there. I would also like to copy the contents of the user address
    > > textboxes to the company textboxes in the "Next" button event handler.
    > >
    > > My problem is that I don't know how to reference these additional
    > > controls. I can see the standard controls included in the base
    > > template but not the controls I add.
    > >
    > > Any ideas or guidance would be greatly appreciated.
    > >

    >
    >
    >
    , Feb 1, 2006
    #3
  4. Guest

    I set tracing on the page and I was able to see one of the controls of
    interest as follows:

    ctl00$ContentPlaceHolder1$CreateUserWizard1
    $CreateUserStepContainer$cboCountry

    I cannot access the CreateUserStepContainer in my code because of its
    protection level.

    "Dominick Baier [DevelopMentor]" wrote:

    > Hi,
    >
    > yeah - controls inside of a template are not placed as a page field.
    >
    > This can be tricky - i am not sure how the CreateUserWizard handles this
    > (have to look) - but the general way is:
    >
    > What i usually do is, enable page tracing in the page directive - and use
    > the FindControl method of the parent control.
    >
    > ---------------------------------------
    > Dominick Baier - DevelopMentor
    > http://www.leastprivilege.com
    >
    > > I am creating a customized CreateUserWizard that has two steps. In
    > > the first step I add controls to collect the user's name and address.
    > > In the second step I collect information about the user's company,
    > > including the company address. I include a checkbox to allow use of
    > > the user's address as the company address.
    > >
    > > Both steps contain a dropdownlist for selecting the state. In the
    > > SelectedIndexChanged event handler on the first page I'd like to
    > > determine the state of the checkbox on the second step and also
    > > reference the dropdownlist on the second step and set the selection
    > > there. I would also like to copy the contents of the user address
    > > textboxes to the company textboxes in the "Next" button event handler.
    > >
    > > My problem is that I don't know how to reference these additional
    > > controls. I can see the standard controls included in the base
    > > template but not the controls I add.
    > >
    > > Any ideas or guidance would be greatly appreciated.
    > >

    >
    >
    >
    , Feb 1, 2006
    #4
  5. Guest

    I was able to work around the issue by writing two page methods:

    protected Control FindWizardControl(string id)
    This method takes the ID of the target control as a parameter and determines
    the number of wizard steps via the CreateUserWizard1.WizardSteps.Count value.
    Then I iterate over those steps using the
    CreateUserWizard1.WizardSteps[stepmumber].Controls.Count. For each control
    in the step I call the second method,

    protected Control FindWizardControl(Control srcCtrl, string id)
    The parameters are a source or root Control and the ID of the target
    control. This method is called recursively until the control is found or
    everything is exhaused indicating the target control ID is not present. The
    approach is to iterate over the child controls of the srcCtrl recursively and
    to break from the iterations when the target control is found.

    The is as follows:

    /// <summary>
    /// Find Wizard Control - Find a control in a wizard
    /// </summary>
    /// <param name="id">ID of target control</param>
    /// <returns>A control reference, if found, null, if not</returns>
    protected Control FindWizardControl(string id)
    {
    Control ctrlRtn = null;

    for (int i = 0; i < CreateUserWizard1.WizardSteps.Count; i++)
    {
    for (int j = 0; j <
    CreateUserWizard1.WizardSteps.Controls.Count; j++)
    {
    ctrlRtn =
    FindWizardControl(

    (Control)CreateUserWizard1.WizardSteps.Controls[j], id);
    if (ctrlRtn != null) break;
    }
    if (ctrlRtn != null) break;
    }

    return ctrlRtn;

    } // end protected Control FindWizardControl(string id)

    /// <summary>
    /// Find Wizard Control - Find a control in a wizard, is recursive
    /// </summary>
    /// <param name="srcCtrl">Source/Root Control</param>
    /// <param name="id">ID of target control</param>
    /// <returns>A Control, if found; null, if not</returns>
    protected Control FindWizardControl(Control srcCtrl, string id)
    {
    Control ctrlRtn = srcCtrl.FindControl(id);

    if (ctrlRtn == null)
    {
    if (srcCtrl.HasControls())
    {
    int nbrCtrls = srcCtrl.Controls.Count;
    for (int i=0; i < nbrCtrls; i++)
    {
    // Check all child controls of srcCtrl
    ctrlRtn = FindWizardControl(srcCtrl.Controls, id);
    if (ctrlRtn != null) break;
    } // endfor (int i=0; i < nbrCtrls; i++)
    } // endif (HasControls)

    } // endif (ctrlRtn == null)

    return ctrlRtn;
    } // end protected Control FindWizardControl(Control srcCtrl, string id)

    Thus far it seems to work. Does anyone have a better approach?

    "" wrote:

    > I set tracing on the page and I was able to see one of the controls of
    > interest as follows:
    >
    > ctl00$ContentPlaceHolder1$CreateUserWizard1
    > $CreateUserStepContainer$cboCountry
    >
    > I cannot access the CreateUserStepContainer in my code because of its
    > protection level.
    >
    > "Dominick Baier [DevelopMentor]" wrote:
    >
    > > Hi,
    > >
    > > yeah - controls inside of a template are not placed as a page field.
    > >
    > > This can be tricky - i am not sure how the CreateUserWizard handles this
    > > (have to look) - but the general way is:
    > >
    > > What i usually do is, enable page tracing in the page directive - and use
    > > the FindControl method of the parent control.
    > >
    > > ---------------------------------------
    > > Dominick Baier - DevelopMentor
    > > http://www.leastprivilege.com
    > >
    > > > I am creating a customized CreateUserWizard that has two steps. In
    > > > the first step I add controls to collect the user's name and address.
    > > > In the second step I collect information about the user's company,
    > > > including the company address. I include a checkbox to allow use of
    > > > the user's address as the company address.
    > > >
    > > > Both steps contain a dropdownlist for selecting the state. In the
    > > > SelectedIndexChanged event handler on the first page I'd like to
    > > > determine the state of the checkbox on the second step and also
    > > > reference the dropdownlist on the second step and set the selection
    > > > there. I would also like to copy the contents of the user address
    > > > textboxes to the company textboxes in the "Next" button event handler.
    > > >
    > > > My problem is that I don't know how to reference these additional
    > > > controls. I can see the standard controls included in the base
    > > > template but not the controls I add.
    > > >
    > > > Any ideas or guidance would be greatly appreciated.
    > > >

    > >
    > >
    > >
    , Feb 2, 2006
    #5
    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. =?Utf-8?B?SmVmZg==?=

    CreateUserWizard - Embedded controls

    =?Utf-8?B?SmVmZg==?=, Nov 12, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    452
    =?Utf-8?B?SmVmZg==?=
    Nov 14, 2005
  2. Zen
    Replies:
    0
    Views:
    1,509
  3. JJ
    Replies:
    1
    Views:
    509
  4. rodchar
    Replies:
    0
    Views:
    374
    rodchar
    Nov 26, 2007
  5. Joe

    CreateUserWizard custom steps

    Joe, Mar 21, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    2,194
    Steven Cheng
    Mar 24, 2008
Loading...

Share This Page