Geeks With Blogs

AzamSharp Some day I will know everything. I hope that day never comes.

I was using CreateUserWizard to create a user. I changed the control so that it contained custom TextBoxes. Now I wanted to get the value out of the TextBoxes. The first approach I tried was the following (offcourse it did not worked!).

TextBox firstNameTextBox = (TextBox) CreateUserWizard1.FindControl("txtFirstName");

This will always return null why? Well it returns null since the TextBox is not contained inside the CreateUserWizard control but its inside a template contained by the CreateUserWizard control. You can easily retrieve the values out of the control using the following code: 

string firstName = ((TextBox)CreateUserWizard1.CreateUserStep
.ContentTemplateContainer.FindControl("txtFirstName")).Text;
        

string lastName = ((TextBox)CreateUserWizard1
        .CreateUserStep.ContentTemplateContainer
        .FindControl("txtLastName")).Text;


               
 

 

 

powered by IMHO 1.3

Posted on Friday, February 17, 2006 7:54 PM | Back to top


Comments on this post: Getting the value out of the control contained in CreateUserWizard Control

# re: Getting the value out of the control contained in CreateUserWizard Control
Requesting Gravatar...
You can use a recursive method, so that you can find a control by id without knowing where the control is actually placed:

http://blogs.ugidotnet.org/simone%20busoli/archive/2006/03/01/35864.aspx
Left by Simone Busoli on Apr 19, 2006 2:40 PM

# re: Getting the value out of the control contained in CreateUserWizard Control
Requesting Gravatar...
you still need to know the ControlID!!
Left by AzamSharp on Apr 19, 2006 2:42 PM

# re: Getting the value out of the control contained in CreateUserWizard Control
Requesting Gravatar...
Of course, what a silly comment! Of course you need to know something about the control you need to get a reference to, otherwise how do you ask for it? [...].FindControl("The nice textbox which is in the template of the CreateUserWizard")?
Left by Simone Busoli on Apr 19, 2006 3:11 PM

# re: Getting the value out of the control contained in CreateUserWizard Control
Requesting Gravatar...
Thank You Azam!
Left by Chris on Feb 17, 2008 4:04 PM

# re: Getting the value out of the control contained in CreateUserWizard Control
Requesting Gravatar...
Thanks very much. Why does MS make it so difficult (and so cryptic) to access controls?
Left by Firoz on Apr 22, 2008 1:43 AM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net