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