StewieHere
StewieHere

Reputation: 43

JQuery set value to custom made server control

We have a custom made server control which several properties defined in it.

<cc1:DropdownCheck ID="ddcStatus"  runat="server" CssClass="ddlchklst" JQueryURL="~/Scripts/jquery.js"
                    Title="Select Status(es)" OpenOnStart="false" divHeight="17px" 
                ImageURL="Images/DropDown.PNG" >
            </cc1:DropdownCheck>

How can I set the value of the Title property on a click event of the server control. My current jquery fn looks like this...

$("#ddcStatus").click(function () {
            //$('#ddcStatus').attr("Title",'Items Selected');
            //document.getElementById("ddcStatus").Title = 'Items Selected';
        });

Both statements didnt work. The getElementById statement gave a script error saying object null.

Upvotes: 0

Views: 764

Answers (2)

oppoic
oppoic

Reputation: 41

Try doing something like that:

$(function(){
    $("#ddcStatus").click(function () {
        //$('#ddcStatus').attr("Title",'Items Selected');
        //document.getElementById("ddcStatus").Title = 'Items Selected';
    });
})

Upvotes: 0

CRDave
CRDave

Reputation: 9285

Problem is in your selector "#ddcStatus" is use to select element with id ddcStatus but it is not same at clint side. You Wil see it something like "abc_xzy_ddcStatus"

ID get changed when page load at client side. so you have two option to solve it

  1. In browser go to source code by selecting view source or by inspect element and find new ID in source and use that ID in jQuery (I don't recommend this way)

  2. use something called dynamic selector which server ID and convert to Client ID by self

$('DropdownCheck[ID$="ddcStatus"]')

you can read this as "select in DropdownCheck whose id ends with ddStatus"

Your solution will not be same replace DropdownCheck with actual control used at client side some help for start with and end with style of jquery

http://api.jquery.com/attribute-ends-with-selector/ http://api.jquery.com/attribute-starts-with-selector/#attributevalue

Upvotes: 3

Related Questions