Tag Archives: Static ClientID

Static ClientID ASP.Net 4.0

Static ClientID
When writing JavaScript code to get any control in a page, We don’t know the control client

ID. Now in ASP.Net 4.0 you can make the client id of the control fixed

By making your control implement the following interface:

INamingContainer “ and set the ClientIDMode property to Static.

For example, here is the codebehind for a simple web user control (ASCX) with a label in it.

public partial class WebUserControl1 : System.Web.UI.UserControl, INamingContainer
   protected void Page_Load(object sender, EventArgs e)
     this.ClientIDMode = ClientIDMode.Static;
That’s all you need to do, and the control gets rendered to the page with an ID of Label1.

Leave a comment

Filed under .Net