Find All Controls ID in ASP.NET WebForms

Posted by Nurasto | September 2, 2013 | Software and Web Development | 0 Comments

Every ASP.NET developer know to find and cast a control but sometimes finding the control name is PITA. I face this kind of problem when still actively programming C# in .NET 2.0 era. So, I have an idea to write junk code in asp.net code behind and throw up into output window rather than putting breakpoints and looking for control ID.

private void ControlExplorer(System.Web.UI.ControlCollection control)
{
	if (control.Count > 0)
	{
		foreach (System.Web.UI.Control currentControl in control)
		{
			System.Diagnostics.Debug.WriteLine(currentControl.GetType().FullName);
			System.Diagnostics.Debug.WriteLine(currentControl.ID);

			this.ControlExplorer(currentControl.Controls);
		}
	}
}

You can call the method inside an control event, choose the target (e.g wizardForm.Controls) and it will print out everything you want. You’re welcome.

Sorry, comments are closed

Bit and Bytes

Hello. My name is Dityo Nurasto. I am working as freelance software and web developer.

This is my personal playground. Enjoy your stay and don't hesitate to send comments.

ShoutBox