Hello everyone.
I have done a lot of reading regarding the recursive issue with FindControl. I have a FormView with an <EditItemTempla te> and all I want to do is add javascript attributes to the form control like this:
smsTxt.Attribut es.Add("onkeydo wn", "backspacerDOWN (this,event);") ;
My goal is to use JavaScript with the ASP.NET controls. I found some code on another forum to do the recursive lookup and here it is:
I have my code to add the attributes in the Page_Load:
I am not getting any errors, but it does not add the Attributes to the control. I don't think it is actually finding the Textbox control. I wrapped the new FindControl in a Class because I was getting an error. Not sure if I even did that right. I am pretty new to .NET programming.
Can someone help me with this? I sure appreciate it!!
Thank you all.
I have done a lot of reading regarding the recursive issue with FindControl. I have a FormView with an <EditItemTempla te> and all I want to do is add javascript attributes to the form control like this:
smsTxt.Attribut es.Add("onkeydo wn", "backspacerDOWN (this,event);") ;
My goal is to use JavaScript with the ASP.NET controls. I found some code on another forum to do the recursive lookup and here it is:
Code:
public static class Utils
{
public static Control FindControl(this Control root, string id, bool recurse)
{
if (!recurse)
{
return root.FindControl(id);
}
System.Web.UI.Control controlFound;
if (root != null)
{
controlFound = root.FindControl(id);
if (controlFound != null)
{
return controlFound;
}
foreach (Control c in root.Controls)
{
controlFound = c.FindControl(id, true);
if (controlFound != null)
{
return controlFound;
}
}
}
return null;
}
}
Code:
TextBox smsTxt = FormView1.FindControl("SMSTextBox", true) as TextBox;
if (smsTxt != null)
{
smsTxt.Attributes.Add("onkeydown", "backspacerDOWN(this,event);");
smsTxt.Attributes.Add("onkeyup", "backspacerUP(this,event);");
}
Can someone help me with this? I sure appreciate it!!
Thank you all.
Comment