Accessing controls from a user control. Please help...

G

Guest

I have an ASP.net user control (userName) that is being dynamically loaded into a panel (pnlSearch) in another user control (userSearch). My question is, how do I access the form elements in userName from userSearch. I am able to manipulate the Visible property along with the ID using the following line of code (dependent upon which property I use

Control userFirst = pnlSearch.Controls[0].FindControl("txtFirstName")
Response.Write(userFirst.ID)

I tried using System.Web.UI.WebControls.TextBox instead of Control, but it would throw an error. If anyone could please help me out I would greatly appreciate it

Jim
 
B

Brian K. Williams

Jim,

Try this, it works for me. :~)
TextBox myControl = (TextBox)FindControl("txtFirstName");

if(myControl != null){

myControl.Text = "Whatever...";

}

Regards,

Brian K. Williams


Jim Mace said:
I have an ASP.net user control (userName) that is being dynamically
loaded into a panel (pnlSearch) in another user control (userSearch). My
question is, how do I access the form elements in userName from userSearch.
I am able to manipulate the Visible property along with the ID using the
following line of code (dependent upon which property I use)
Control userFirst = pnlSearch.Controls[0].FindControl("txtFirstName");
Response.Write(userFirst.ID);

I tried using System.Web.UI.WebControls.TextBox instead of Control, but it
would throw an error. If anyone could please help me out I would greatly
appreciate it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top