Getting value from textbox within the CreateUserWizard

Last post 11-02-2007 6:51 AM by wizzkidd07. 4 replies.

Sort Posts:

  • Getting value from textbox within the CreateUserWizard

    10-28-2007, 4:59 PM
    • Member
      25 point Member
    • wizzkidd07
    • Member since 10-21-2007, 11:18 AM
    • London, United Kingdom
    • Posts 65

    I am trying to populate a label with the value of a textfield, BUT, the textfield is within the CreateUserWizard.

    I've read many posts describing the FindControl method, however I cant seem to get the context right.  For clarity I am trying to populate a label, but once I am happy I will be happy just populating a string variable, because I aim to use the variable in the code behind.

    Due to the fact that I would like to populate a Label field which resides on the 2nd (last) step of the CreateUserWizard, I'm guessing that the Label control will have to be 'found' too using FindControl.  So this is what i've come up with...

    TextBox _txtEmailAddress = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EmailAddress");
    Label _lblEmailAddress = (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("lblEmailAddress");
    _lblEmailAddress.Text = _txtEmailAddress.Text;

    "EmailAddress" is the ID of the Email Address textbox field on the 1st step of the CreateUserWizard, hence why I state:
    (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EmailAddress");
    and having read posts, it appears I must cast the control to its assosiated type, in this case TextBox as shown above. (please note my terminology is not very good as I am still learning the correct terms of what to call each item/property/container etc) So, I have then made a 'variable?' of type TextBox called _txtEmailAddress, and this holds the control (if im correct).

    I have applied the same practice to the Label, but instead I have changed it to use CompleteStep instead of CreateUserStep, and done a FindControl on the lblEmailAddress (this is the ID of the Label on this step), and casted it as type Label in a similar fashion.

    Now I've obviously done something wrong because when i put:
    _lblEmailAddress.Text = _txtEmailAddress.Text;
    I would expect the Label to populate with the text value from the textbox.

    Could someone kindly explain my faults? I am sure you can respect that I am not simply trying to copy and paste code, butI am trying to understand the concepts and methods behind the way things are done and suggested by everyone.

    Lastly, if someone manages to explain a way to do this, am I correct in saying that if the code was correct, I could populate a string variable, lets say:
    string myEmailAddress, with the EmailAddress textbox value from the CreateUserStep?

    Thanks in advanced.

    - WizzKidd

    - WizzKidd
    - http://www.PromotionCity.co.uk
    Filed under:
  • Re: Getting value from textbox within the CreateUserWizard

    10-30-2007, 3:15 AM
    Answer

    Hi,

    From your description, it seems that you are unable to get the Label or Textbox instance in the CreateUserWizard control, right?

    I think before you use findcontrol method in your code behind file, you should click on the small back arrow on the CreateUserWizard control, and click on “Customize Create User Step”. After it, use the findcontrol method to access the child control of your CreateUserWizard. i.e:

           TextBox tb = (TextBox)this.CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email");
            tb.Text = "abc";

            Label lb = (Label)this.CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EmailLabel");
            lb.Text = "Please input the Email Addr:";

    Thanks.

    Michael Jin.
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Getting value from textbox within the CreateUserWizard

    10-30-2007, 5:42 AM
    • Member
      25 point Member
    • wizzkidd07
    • Member since 10-21-2007, 11:18 AM
    • London, United Kingdom
    • Posts 65

    Ok, half of my problem when doing a stepthrough, was that these lines were not being accessed cause I had them in a function and silly me was not calling the function anywhere.  But now I have that sorted.

    It appears my method is almost working (which is literally the same as your example above) but bare in mind that in my example I will be populating a label in the 'CompletedStep' with the value from the textbox in the 'CreateUserStep'...

    TextBox _txtEmailAddress = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EmailAddress");

    Label _lblEmailAddress = (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("lblEmailAddress");

    _lblEmailAddress.Text = _txtEmailAddress.Text;

     

    I get an error complaining about setting a new instance?

    - WizzKidd
    - http://www.PromotionCity.co.uk
  • Re: Getting value from textbox within the CreateUserWizard

    10-30-2007, 11:58 PM

    Hi,

    You got an error complaining about a new instance?  Is it "Object reference not set to an instance of an object."

    If so, the error message means you can't access the TextBox or the label's instance. Please try to make sure if the name listed in FindControl method equals with the name of the control it defined in CreateUserWizard control.

    Besides, you have assign the text value of the textbox to the text property of the label, if so, nothing will displayed in the label since the text value of the textbox is empty by defalut.

    Thanks.

    Michael Jin.
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Getting value from textbox within the CreateUserWizard

    11-02-2007, 6:51 AM
    Answer
    • Member
      25 point Member
    • wizzkidd07
    • Member since 10-21-2007, 11:18 AM
    • London, United Kingdom
    • Posts 65

    Thanks for all your help guys.  I've managed to get it working now.  I'm just getting used to the error messages and what they mean.  Im very used to classic asp using vbscript, so debugging those errors where a breeze.

    Anyway, I eventually figured out that the "new instance" error message boiled down to the fact it could not find the control i was looking for.  I realised my control was not called "EmailAddress", and it was actually called "Email".  So the following worked fine:

    TextBox _txtEmailAddress = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email");

    Label _lblEmailAddress = (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("lblEmailAddress");

    _lblEmailAddress.Text = _txtEmailAddress.Text;

    - WizzKidd

    - WizzKidd
    - http://www.PromotionCity.co.uk
Page 1 of 1 (5 items)