views:

382

answers:

3

The button is derived from user control. I want to associate a pop-up window on click of that particular butoon. I can able to achieve this on click of anyother buttons on my base page but as that particular button is coming from a user control I am not able to trigger the pop-up window. Need help.

$('#btnSendOrder').click(function() {// code here}) // btnSendOrder is from a user control.In this case pop-up is not coming.

$('#btnSendOrder').click(function() { // code here}) // btnSend Order is from the base page itself. In this scenario pop-up comes out.

A: 

Using a bit of jquery, it would be relatively trivial to associate the button with a click event on load of the page:

    $(".button").click(function() {
        PopupMyWindow();
    });
Paddy
A: 

If you are using .NET, reember that your controls will end up looking something like: ctl1.UserControlName.ButtonName or something like that.

Check your markup code once it is rendered, then use the exact button name so that your jQuery knows which control to fire from.

Jack Marchetti
Thanks for this trick.
Also take a look at what @Juan Manual did below. Ideally you should grab the ClientID, instead of hard coding it because depending on where that button lives in your app, its clientID might change. Just a heads up.
Jack Marchetti
+1  A: 

Since the button is being rendered on the server, its client ID is not what you are using

You can do this...

$('#<%= btnSendOrder.ClientID %>').click(function() {// code here})

... from your usercontrol, and the portion between <% and %> will be replaced with the real control id in the client html

Juan Manuel