.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Rendered ClientID is Different from Programmatically Retrieved ClientID

Posted By:      Posted Date: September 26, 2010    Points: 0   Category :ASP.Net


I get the ClientID of a control in ItemCreated event like this: 'ctrl0_spanLoader'

and when it is rendered like this (from view source of IE): 'CtlCategory1_ProfiledBasedSearchResult1_ListViewSearchResult_ctrl0_spanLoader'

This happens in Asp.Net 4 and I have no problems in Asp.Net 3.5.

How do I get the real clientID from ClientID property of my control? Is it a matter of configuration or anything else?

View Complete Post

More Related Resource Links

.net 4 framework getelementbyid for javascript without clientid


I thought I heard we would be able to get the value of an asp:textbox by id with javascript in the .net 4 framework? was I mistaken? if not does anyone know the syntax?

What's the problem in my javascript's code to get ClientID Property?



 Hi all.

I wirte a simple java script code to get ClientID of controls on the webform. The code is like:

<script type="text/javascript" language="javascript">

var butt = $find("<%= Button1.ClientID %>");



But when i run it , i have a problem. The probmel is:


Server Error in '/' Application.

The Controls collection cannot be modified because t

Can't get ClientID of ASP control in Rendering template

Hi, I've made custom field with its own rendering template. Inside template i need to show/hide some controls, but i cant get ClientID of them. Inside rendering template : <%@ Assembly Name="XXX, Version=, Culture=neutral, PublicKeyToken=72277ea422a3515d" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Control Language="C#" AutoEventWireup="true&q

Control.ClientID with ASP.NET and jQuery - Where am I going wrong?

 Hey everyone.  I've got some jQuery on in a User Control which takes the values from two hidden field and uses them against a jQuery UI Multi-handle Slider and two ASP.net Textboxes.  When I drop this User Control on a Content Page, my control names are renamed from 'txtStartTime' to 'MainContent_UserControl_txtStartTime'...  This is a problem because now I have all the controls hard-coded by ID... but if I want to use the jQuery in another User Control, I'll have to rename everything.  That sucks.This is why I want to learn how to use the Control.ClientID via jQuery to get a controlID.  For instance, how would I change this to use ClientID? $('#MainContent_ucAddEvent_txtStartTime').val(getTime($('#MainContent_ucAddEvent_hfStartTime').val())); $('#MainContent_ucAddEvent_txtEndTime').val(getTime($('#MainContent_ucAddEvent_hfEndTime').val())); //Function GetTime takes t (Ticks/Integer) and converts it to a 00:00:00 format. function getTime(t) { var t_h = Math.floor(t / 3600); var t_m = Math.floor(t / 60) - (t_h * 60); var t_s = t - (t_h * 3600) - (t_m * 60); var f_t = (t_h < 10 ? '0' + t_h : t_h) + ':' + (t_m < 10 ? '0' + t_m : t_m) + ':' + (t_s < 10 ? '0' + t_s : t_s);

Pass Javacript to Custom Control with ClientID

Hello,Can someone help me with this.  I have a custom control that I have created.  I want to be able to pass in a Javascript snippet for a callback function.  I am able to do this by passing a string back.  The problem is that in the Javascript, I need to reference another server control that is not related to my custom control.  So, I need to be able to pass in the ClientID of that control for use in the Javascript.  Here is a snippet of what I am trying to do:<asp:CheckBox ID="chkStartDate" runat="server" /><cc:MyNewControl id="MyControl1" runat="server" OnClientOnChangeEvent="toggleCheckBox('<%= chkStartDate.ClientID %>');" /> Now, I realize that '<%= chkStartDate.ClientID %>' will not be parsed.  But, I need it to be parsed so the OnClientOnChangeEvent property of my custom control can take any Javascript for use as a callback. In this instance, I need to pass in the ClientID of the control for the Javascript function to find the control to work with; and this seems to be the one issue that I don't know how to handle. I would appreciate any help offered for this.Thanks in advance.

adding ClientID to server control


hey all,

need help withthis one...

I need to add ClientID of one control to another server control attribute

this line works

<div content="<%= challengesTab_content.ClientID%>"  id="challengesTab">Challenges</div>

but when I add runat=server it doesn't get the clientid and just renders whatever is in content attribute

<div runat="server"  content="<%= challengesTab_content.ClientID%>"  id="challengesTab">Challenges</div>


so is there any way I can do it since I want to access this control on server side :s


Workin with ClientID


Hi Experts.

I use the " var btn = $get('<%=Button1.ClientID%>'); " in javascript code. when i palce this script after form tag, it run and return object, but when i place this script inline head tag or is writen into another jscript file, its return null, Why? How can i solve this problem?


clientId inside a repeater to a JavaScript Function

<a href="javascript:setting('ViewProfile','1','hdViewName');"/>
I have this anchor control inside a  Repeater. The javascript function need to pass the client id of the hidden field which is also inside the repeater. The problem is that I don't know the client id of the hidden field inside the repeater control in advance.The id is like ctl00......00hdnvalue and the id changes with the number of repeater items. Is there a solution for this situation?

How to add current clientID to table


Hello, I am trying to create a listing for a ticket company. When the user(client) adds a new ticket to the listing, all the ticket info is saved into the database table, but I can't figure out how to get their clientID in the table with that post. For example, I have event, date, venue, row, section etc...all this info gets stored, but I need to have the clientID stored also, so the gridview can show the post when the client logs in/out from the app. Right now the only way the clientID is in the DB is because I manually put it there for development reasons. But, when the client adds a new item to their listings, it does not show until I put the ID in myself. I need the ID to insert in the CID column at the same time the rest of the info is stored.


Any help would be much appreciated. Thanks in advance. 

Grab the clientid of a dynamically added control


Hi all,

I add CompareValidators dynamically in my code behind. I need to access these controls within javascript to see if they are active or not. Whats the best way to do this?

The button that calls this javascript is also added dynamically. I dont know how many validators I add and they are added via a loop. I add the name to a string which I pass into my JS function, so within JS I have access to all validators added. Heres my code behind which creates the validators:

CompareValidator CV = new CompareValidator();
CV.ID = "CV" + parameter.Name;
CV.Type = ValidationDataType.Date;
CV.Operator = ValidationCompareOperator.DataTypeCheck;
CV.ErrorMessage = "* Invalid date";
CV.Display = ValidatorDisplay.Dynamic;
CV.ControlToValidate = parameter.Name;
CV.ValidationGroup = "valGroup1";
CV.Style["font"] = "Arial";
CV.Style["color"] = "Red";
CV.Style["font-size"] = "10px";


if (validators != "")
validators += ":" + CV.ClientID;
validators = CV.UniqueID;


I then add my button passing in 'validators' string:

HtmlInputButton btn = new HtmlInputButton();
btn.Value = "Run Report";
btn.ID = "Ru

Giving same ClientID for all the Rows of the GridView


HI All,

 I am using GridView in my web application.I am trying to fetch the Row ID of the grid. All are Bound Field only. I have written the following code. Previously i was getting each row ID. But now i changed in the Datafield to some other property and trying to run i am getting the same Row Id(that is GridView id) for all rows of GridVIew in View source of that page.

My requirement is after getting the row , i need to change the row color. This is my code.

  protected void dgFileUploadSummary_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.DataRow)

how to substitute a variable for getElementById("<%=fieldname.ClientID%>").value


in the following function, I am trying to substitute a variable for the fieldname rnRAPORAmount1in the line:

RAP = document.getElementById("<%=rnRAPORAmount1.ClientID%>").value;

I have the fields rnRAPORAmount1 to rnRAPORAmount65 sequentially i.e. 65 fields on my form and need to do validation on each one. The function as is works fine however I'd rather not write it out 65 times. I've been trying to do something like:

var i = 1 where the value of i is determined by which 'this.id' I'm validating

RAP = document.getElementById("<%='rnRAPORAmount' + i.ClientID%>").value;

but nothing works. Thanks a lot for any suggestions!

<asp:RadioButtonList ID="rbRAPType1" runat="server"  RepeatDirection="Horizontal" onClick="return ValidateRAP(this.id);" >
 <asp:ListItem Value="R"> RAP </asp:ListItem>
 <asp:ListItem Value="O"> OR </asp:ListItem>
 <asp:ListItem Value="N"> NA </asp:ListItem>

function ValidateRAP(field) {
 alert("field= " + field);
 var i = 1
 radioButtons = document.getElementsByName(field);
  for (var x = 0; x < radioButtons.length; x++) {
   if (radioButtons[x].checked) {
   alert("You checked " + radioButtons[

Export SharePoint List to Excel Spreadsheet Programmatically using C#

In SharePoint applications, Custom Lists are used to store business data and Document Libraries to store the documents. But for data manupulation and analysis, Microsoft Excel provides very rich features as compared to SharePoint Lists. That's why people still loves to work on Microsoft Excel Sheets.

Creating an Excel Spreadsheet programmatically using VB.NET

The Interoperability services make it very easy to work with COM Capable Applications such as Word and Excel. This article reveals using Excel from a managed application. Excel is the spreadsheet component of Microsoft Office 2000. The majority of Excel programmatic functionality is exposed through Automation via the type library Excel9.olb. The intention of this article is to express that a managed application can interrelate with Excel as a COM server.

Creating an Excel Spreadsheet and Adding Data to It Programmatically

The Interoperability services make it veryeasy to work with COM Capable Applications such as Word and Excel. Thisarticle reveals using Excel from a managed application. Excel is thespreadsheet component of Microsoft Office 2000. The majority of Excelprogrammatic functionality is exposed through Automation via the typelibrary Excel9.olb. The intention of this article is to express that amanaged application can interrelate with Excel as a COM server.

How to programmatically add controls to Windows forms at run time by using Visual C#

Create a Windows Forms Application
Start Visual Studio .NET or Visual Studio 2005 or a later version, and create a new Visual C# Windows Application project named WinControls. Form1 is added to the project by default.
Double-click Form1 to create and view the Form1_Load event procedure.
Add private instance variables to the Form1 class to work with common Windows controls. The Form1 class starts as follows:

Tab container rendered with visibility:hidden - This was reported over three years ago.



Here is (more) code that demonstrates the issue.  If the control in the host page is removed the tab control renders correctly.  Otherwise it is rendered with the visibility attrubute set to hidden as reported in the above link.  Is this broken or am I doing something wrong?



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="S2.aspx.cs" Inherits="S2" %>
<%@ Register Src="~/SelectorPatternControl.ascx" TagName="TestControl" TagPrefix="sam" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <cc1:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></cc1:ToolkitScriptManager>
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend