Click here to Skip to main content
12,695,743 members (29,893 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked

How to Get User Controls ClientID in JavaScript in aspx Page

, 16 Apr 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Get ClientID of User control which is register on Page In JavaScript.


There are lots of times when we access user control in our web application, At the time of using user control, we want to access this User control in JavaScript. Given below is the problem and solution for accessing user control in JavaScript.


While using user control, we want to access this user control in JavaScript, and we try to get its Client ID. But by using document.getElementById('<% =UserControl.ClientID%>'), it returns null value.


To overcome this problem, we create one function in UserControls code behind like "GetClientID" - it returns the Clientid of the control, then we can easily access the same.

Follow the Steps

  1. Create a Web Application, add a Web User Control by clicking add new Item.
  2. Write the below code in User Control:
    Public Function getClientID() As String
            Return Controls.ClientID
    End Function
  3. After that, register this user control in your aspx page by adding the below tag:
    <%@ Register Src="~/WebUserControl.ascx" TagName="Test" TagPrefix="uc2" %>
  4. After that, add JavaScript tag in aspx head section.
    function FunctionName {
  5. It shows the value of control which is used in user control.


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


About the Author

Dnyaneshwar Kondbale
Software Developer (Senior)
India India
No Biography provided

You may also be interested in...


Comments and Discussions

SuggestionUse Findcontrol instead Pin
AminSh13-Oct-15 5:25
memberAminSh13-Oct-15 5:25 
SuggestionHow to Get User Controls ClientID in JavaScript in aspx Page Pin
Ravishankar M17-Jul-13 3:12
memberRavishankar M17-Jul-13 3:12 
QuestionGood Pin
Member6118-Apr-13 2:25
memberMember6118-Apr-13 2:25 
GeneralMy vote of 3 Pin
Rohan Leuva17-Apr-13 0:31
memberRohan Leuva17-Apr-13 0:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 17 Apr 2013
Article Copyright 2013 by Dnyaneshwar Kondbale
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid