Solved

How to Trigger JQuery function from code behind

Posted on 2011-03-21
3
948 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

809 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