How do I make the ID of my textbox assign in the property of the usercontrol?

I am using a datagrid to display a set of records, and I am generating controls for each column dynamically in ASP.NET page. The first column of the datagrid contains a usercontrol and the second column contains a textbox. Both are generated dynamically. But I want the ID of the textbox to assign in the property of the usercontrol. How to do that? Please help me.
You could assign a fixed ID to the textbox, such as txtTextbox, and to the user control, such as usrControl. Later on, you can handle the ItemCreated event (or the ItemDataBound) and use the FindControl method to locate both your user control and the textbox and assign the property you need:
private void theGrid_ItemCreated(object sender, DataGridItemEventArgs e)
 Control usr = e.Item.FindControl("usrControl");
 Control txt = e.Item.FindControl("txtTextbox");
 //Assign the prop.
 ((MyUserControl)usr).TheTextBoxID = txt.ClientID;

This was first published in November 2003

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: