Solved

How to Trigger JQuery function from code behind

Posted on 2011-03-21
3
950 Views
Last Modified: 2012-05-11
Is it possible to trigger a JQuery function from code behind?  I have attached the JQuery function and a couple screen shots reflecting what happens when you click on the image/link (screenshots reflect closed and open state).

Any help is very much appreciated.  

I am trying to trigger the click event from code behind, so I can essentially show the open state.  The reason is because when you click on "Sign in" it posts back.  If user is not authenticated, I display a message below the textboxes. Right now, since page is posting back, the control returns to closed state.  

<script type="text/javascript">
    $(document).ready(function () {

        $(".signin").click(function (e) {
            e.preventDefault();
            $("fieldset#signin_menu").toggle();
            $(".signin").toggleClass("menu-open");
        });

        $("fieldset#signin_menu").mouseup(function () {
            return false
        });
        $(document).mouseup(function (e) {
            if ($(e.target).parent("a.signin").length == 0) {
                $(".signin").removeClass("menu-open");
                $("fieldset#signin_menu").hide();
            }
        });
    });
</script>

Open in new window


Closed State
Open State
0
Comment
Question by:obautista
3 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35186183
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
ID: 35186967

// Try something like this:

String script = @"
<script language=JavaScript>
  alert( 'Calling my Javascript function...' );
  $('.signin').trigger( 'click' );
</script>
";

this.RegisterClientScriptBlock( "myScript", script );

0
 

Author Closing Comment

by:obautista
ID: 35186995
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question