Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Showing posts with label FindControl. Show all posts
Showing posts with label FindControl. Show all posts

Saturday, February 16, 2008

FindContol Solution to add Javascript to a control from a user control

Here is a great solution to finding a control using FindControl method from a user control. TargetcontrolID is the public property for TextBoxFooExtender (User Control). _txt is the targeted TextBox assuming it is found.

protected override void CreateChildControls()
{
txt = (TextBox)this.Parent.FindControl(TargetControlID);
if (txt != null) {
_txt.Attributes.Add("ondblclick", "alert('foo')");
}
base.CreateChildControls();
}