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

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

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

Posted By:      Posted Date: September 04, 2010    Points: 0   Category :ASP.Net
 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);

View Complete Post

More Related Resource Links

find a Control inside a GridView using jQuery


I have databound GridView in my page and I have a hidden DIV in all rows. Each row contains a Button that I want it to make the DIV visible for me! how can I use that with jQuery?!

here is the code page: 

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                                EnableModelValidation="True" GridLines="None" ShowHeader="False" Width="100%">

Jquery date picker in ASP.NET Web user control does not work


Hello, I have the most frustrating problem and being new to JQuery does make it more difficult. I have an ASP.NET web user control with an ASP.NET box which I want to apply a JQuery date picker to, then of course I have server side code which takes the date and processes it etc. The date picker will not work. I can achieve a working JQuery date picker with an ASP.NET textbox if there is no user control involved, or within the user control I use a html text box instead, but once I add runat="server" to the text box, it does not work. Is there a way I can achieve this? (the web user control will be wrapped in an update panel too which at the moment will work with the html control/web user control without the server side functionality)

<%@ Register TagPrefix="TE" TagName="JobHistory" Src="test.ascx"%>

<!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">


    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <link h

how to get the text of selected checkbox from asp.net checkboxlist control using jquery


I have asp.net checkboxlist control that bounded to a data source so the number of items in the control are different from one to to another time.

I have this function:

     $('#<%=chkListGroups.ClientID %> input:checkbox:checked').siblings('label').text();

this function will return all texts for all selected items in the control as a one string.

 I'm looking for a way that when I check a check box from the ckeckboxlist control will return only last checked checkbox.

this code :

$('#<%=chkListGroups.ClientID %> input:checkbox:checked').last().siblings('label').text(); 

returns last checked item for example if I checked second will return
second item then when I checked fifth item will return fifth item but
if now when I check third item will return fifth item so it is always
returning last item checked in the list and I'm looking to

Please advice me how to do this using jquery.

using jquery tooltip with asp:Chart control


I'm trying to use qtip (jquery plugin) instead of the standard tooltip control provided for the asp:Chart. I think the best way to do this is with an img map, though I don't know how to implement it. Does anyone know how to implement the img map for an asp:Chart?

jQuery Rating Control in Repeater - Not Duplicating per Record

Hi Everyone,There is a similar instance of this @ http://forums.asp.net/p/1380776/2919093.aspx#2919093 However I haven't had a response, maybe due to the age of the topic, but the problem is different in the sense I am not using AJAX Rating Control, I am using radio buttons contained in a Div named Ratings, which is picked up by jQuery to style to radio buttons accordingly. The output is that it will put the stars on the first record but anything after just shows origional unstyled radio buttons. Just thinking off the top of my head, but does anything need to be put in the ItemDataBound event? The jQuery for the stars etc were attained from the link below:http://orkans-tmp.22web.net/star_rating/index.html#demos=&main-menu=0&demo-tabs=3 Here is my code:.ASPX:<%@ Page Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Admin_Test" Title="Untitled Page" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <asp:Content ID="Content1" ContentPlaceHolderID="CPCHeader" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="AdminCPC" Runat="Server"> <asp:R

Need urgent help using JQuery DatePicker inside asp.net user control

Hello,I am able to use the DatePicker inside an aspx page with no problem at all but when I try to use that inside a usercontrol it gives me an error "Object expected"I have the links to my Jquery css and script files from the master page and have the following code inside a usercontrol:<script type="text/javascript"><!--    $(document).ready(function() {    var txt1 = document.getElementById('<%= txtDate.ClientID %>');    $(txt1).datepicker({ dateFormat: 'dd/mm/yy', duration: ''   });    });          // --></script><asp:TextBox ID="txtDate" runat="server"></asp:TextBox>

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

How do grab the value from label control into jQuery?

I have the following jQuery code working as it is (passing the value of 'test") but what I want to do is to pass the value of the label control (lblNames). I'm using the label control to collect the uploaded file names. Is there a way?jQuery:$(document).ready(function () {        $("#btnUpload").click(function () {            $("#Notes", top.document).val('test');        });    });ASPX code:<asp:Label ID="lblNames" runat="server" visible="true" ></asp:Label>

How to embed jquery library in ASP.NET Custom Server Control

i created custom server control using jquery. i  embeded  jquery library in the control using following code. but it displays object expected error.  has someone done this before ?   //other code    protected override void RenderContents(HtmlTextWriter output) {    output.Write("<div id=\"bckPopup\"></div>"); }   protected void onInit(EventArgs e) { Page.ClientScript.RegisterClientScriptResource(GetType(), "HelpServerControl.Scripts.jquery-1.4.1.min.js");   string javascript = "<script type='text/javascript'> " +   "$(document).ready(function () { " +   "$('#bckPopup').text(\"loaded\"); " + "});</script>" ;   if (!(Page.ClientScript.IsClientScriptBlockRegistered("bhelp" ))) Page.ClientScript.RegisterStartupScript(this.GetType(), "bhelp" , javascript); base .OnInit(e);   }      

Enters trigger the wrong control

How can i choose what button is activated when a user presses Enter after for example filling out  a textbox?

Jquery Append Asp control

 Hi, I have problem to append asp control into my table. error msg:  'Text' + index + '' is not a valid identifier.var index = 1; $('#table').last().append('<asp:TextBox ID="Text' + index + '" runat="server" CssClass="DDTextBox" />');

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.

User Control with JQuery doesnot work inside update panel


Hi All,

I created a .NET user control to work as a DropdownCheckbox and added Jquery to give the sliding and hide effects. The code is as below:

 <script language="javascript" type="text/javascript">
        var showRegionWindow = function (ev) {
            var pos = $("#lnkChangeRegion").offset();
            var width = 230;
            var height = 55;
            //$("#changeRegionPanel").css({ "left": +((pos.left) - 215) + "px", "top": height + 16 + "px" });.
            document.getElementById("lnkChangeRegion").style.display = 'none';

        var hideRegionWindow = function (ev) {
            var textVal = "";

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


DataAnnotation on multiple user controls displaying on wrong control


I have a table that displays a user control on each row. The user controls are strongly typed to a viewmodel which contains DataAnnotation style validation. If one of the rows has invalid data entered (lets say the 3rd row) the data annotation validates display agains the first row/user control.

How do I get the data annotation to show against the relevant user control?

I'd post a pic to show what I mean except it will not display it!.:/

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

Request for discussion points Ajax Control Toolkit vs JQuery


There is some talk in our office about not using the Toolkit for future projects and replacing it with JQuery. Myself and one other have made extensive use of the Toolkit and are fine with it other than some problems with the latest version and ASP.NET 4.0 and some difficulty when debugging. 

Has anyone made an effort to seriously compare and contrast the two options and show how one might replace tab controls, modal popup extenders and others with JQuery?

I realize this is a forum for the Toolkit and am interested in answers from supporters.


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