views:

69

answers:

2

i have this in my content page: but i am getting null value if i try $("#ctl00_cphMaster_CloseButton").

$(document).ready(function() {
    $("#ctl00_cphMaster_CloseButton").click(function() {
            jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
                if (r == true)
                    __doPostBack('CloseButton', '');
            });
            return false;
        });
    });
});

<uc1:ImageTextButton ID="CloseButton" runat="server" 
            ImageURL="Images/closeIcon.png"
            Enabled="True" Text="Close" 
            CausesValidation="false" onclick="CloseButton_Click" />

UPDATE:

i have tried like this:

$("#<%= CloseButton.ClientID %>").click(function() {

        jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
            if (r == true)
                __doPostBack('CloseButton', '');
        });
        return false;
    });
});

when i run my page it throws me an error with this code:

$("#ctl00_cphMaster_CloseButton").click(function() {

        jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
            if (r == true)
                __doPostBack('CloseButton', '');
        });
        return false;
    });

it means it got the right id but why is it throwing an error complaining about null

Microsoft JScript runtime error: 'null' is null or not an object

UPDATE:

KP Suggestion:

$("#<%= CloseButton.ClientID %>").click(function() { 
             alert("yes");
       }); 
});
+1  A: 

Have you tried to use the ClientID-Property of the button-control?

$("#<%= CloseButton.ClientID %>")
john_doe
i updated my question.
Abu Hamzah
A: 

I'd go with $("[id$=CloseButton]") which matches elements which end with CloseButton

Nico
i get the same error null;
Abu Hamzah
run $("[id$=CloseButton]") in firebug, if the console displays the element as found, then the problem is elsewhere in the code.
Nico
i tried in VisualStudio Qucikwatch and it returns me "null" and also tried in immedidate window same thing.
Abu Hamzah
I think the simplest solution I can give you is to load the proyect in firefox, with firebug, and inspect the element to find out what the ID of your control is, and build your selector around that. You can also just look at the source for the page and find the ID there.
Nico