Triggering jQuery click() From ASP.NET Master Pages

MinnRick
MinnRick used Ask the Experts™
on
Hello Experts -
I'm trying to wire up a code-behind-run click event for a DIV on an ASP.NET master page.  In searching for a solution the most common suggestion that I have seen is to create and hide (using CSS) a button control somewhere on the master page and then code up the jQuery (inside $(document).ready) something like this:
$('#div').click(function () {
   $('#HiddenButton').click();
});

Open in new window

This works fine on a non-master page but I can't get it to work on a master, regardless of where I put the jQuery code.  Is there some unique insight or a special technique that I need to know about to get this to work on a master page structure?  Thanks!

-- Rick
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
if you put alert in master pages.is it firing?
$('#div').click(function () {
alert("hi")
   $('#HiddenButton').click();
});

or try this;

$('#div').live('click',function () {
alert("hi")
   $('#HiddenButton').click();
});
Project Lead
Top Expert 2011
Commented:
1) Check the view source (right click on browser & view source). Button you are hiding, the id of button should be "HiddenButton"
2) OR add class to button (CssClass='hidebutton') then your jquery function will look like
$('#div').click(function () {
   $('.hidebutton').click(); // OR $(".hidebutton").trigger('click');
});

Author

Commented:
No luck with either on() or trigger() - thanks for the attempt chaituu.

Sona:  Yes!  The ID for the hidden button is different in the markup for the rendered (child) page than is specified in the master page from which it originated.  I'm assuming that the reason lies in the whole master/child page model somehow.  In any case, setting a CSS class for the hidden button and wiring it up the jQuery click() for the DIV worked perfectly.  Thanks very much.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial