Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Hi I'm using user control in my aspx page i want to get the text box control id and values which are in user control. plz refer me how to find the control from user control.


Regards
Prashanth
Posted

C#
Textbox t1 = UserControl1.FindControl("textbox1") as Textbox;


Usercontrol1 is the instance Id of your user control inside your page

t1 will be assigned (by reference) with the found textbox control.

mark as answer if solves your problem.
 
Share this answer
 
Comments
BobJanova 1-Nov-11 7:18am    
While this will work it is surely better for the user control to expose the relevant values as properties.
Try this:

TextBox TextBox1 = (TextBox)WebUserControl1.FindControl("TextBox1");
GridView GridView1 = (GridView)WebUserControl1.FindControl("GridView1");
 
Share this answer
 
If you don't want to use FindControl and want to have a strongly typed variable in your code ,
Add a TextBox type property to your user control and return the textbox control reference in its get method :
C#
public TextBox InternalTextbox
{
    get
    {
        return TextBox1;
    }
}


By this way you grant outsiders of your user control, the access to internal Textbox1 control.
 
Share this answer
 
thanks guys for your replys
i got found

TextBox txtDistrict =(TextBox) LocProduct.FindControl("txtDistict");
Prashanth
 
Share this answer
 
Comments
Pandya Anil 1-Nov-11 9:26am    
mark as answer to solutions, who has halped you...
And one more problem i want get usercontrol's public varible in my .cs file
 
Share this answer
 
Comments
Pandya Anil 1-Nov-11 9:28am    
the public members are directly accesible...
use in page like string s1 = UserCOntrol1.strVariable1;
if the strVariable1 is public member it will be accessed.
prashanth reddy pola 1-Nov-11 9:41am    
Anil I am Unable to accepting varible

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900