Click here to Skip to main content
12,395,645 members (81,309 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads

Stats

205.6K views
484 downloads
21 bookmarked
Posted

ASP.NET: How to Resolve Client ID

, 1 Feb 2007 CPOL
A method to resolve the client IDs of controls in containers.
/// <summary>
/// FileName: mycontrol.ascx.cs
/// 
/// Purpose: controls container
/// 
/// Author: 0garcia (og-bit.com) 
/// 
/// Update/Fix History:
/// 0g01302007 Initial Implementation
/// </summary>

namespace ResolveClientId
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>
	///		Summary description for ValidateControl.
	/// </summary>
	public class myControl : System.Web.UI.UserControl
	{
		protected System.Web.UI.WebControls.TextBox mytext;
		protected System.Web.UI.WebControls.Literal   ctrlPrefix;

		private void Page_Load(object sender, System.EventArgs e)
		{			
			string name = this.ClientID;
			string []elm =ctrlPrefix.ClientID.Split('_');		//get an array of values 
			ctrlPrefix.Text = ctrlPrefix.ClientID.Replace(elm[elm.Length - 1],"");    //get the last element and replace from the id     
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

ozkar garcia
Architect OG-BITechnologies
United States United States

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 1 Feb 2007
Article Copyright 2007 by ozkar garcia
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid