Skip to content Skip to sidebar Skip to footer

Failed To Get Server Control Id

I using .ascx I am trying to use my jQuery to perform some action, the below code is how I call server control id. $('input').mouseenter(function() { //some function }

Solution 1:

Use:

$("#<% family2.ClientID %>").mouseenter(function() {
    //some function
 }

because you can reuse your control, asp.net is adding some prefix to your ID. This resulting ID varries from page to page. You can check which is the resulting ID on your page and hardcode the ID into the jQuery Selector but using clientID is the way to go. You can use it on all pages with your control without worries.

Solution 2:

Use this ClientIDMode="Static"

 <inputtype="text"id="family2" ClientIDMode="Static" value="family" runat="server"/> 

Edit 1

ClientIdMode="Static": This is most basic, simple mode and it makes the client side ID static. Whatever value you put for the ClientID or ID is that which will be used for the client side ID. One odd condition here, if a static ClientIDMode is used in a repeating control, the developer is responsible for ensuring client side ID uniqueness. http://www.codeproject.com/Articles/34151/ASP-NET-4-0-Client-ID-Feature

Solution 3:

 $(document).ready(function () {
        $('.ctl00_m_g_3b0d8e69_1961_4bea_886d_413493ff7f9c_ctl00_checkclass').hover(function (event) {
            alert('dada');
            var c = alert($(this).attr("id"));
            alert(c);
        });
    });


<inputtype="text"id="family1"value="family1"class="checkclass"/><inputtype="text"id="family2"value="family2"class="checkclass" /><inputtype="text"id="family3"value="family3"class="checkclass" />

Post a Comment for "Failed To Get Server Control Id"