Solved

How to Trigger JQuery function from code behind

Posted on 2011-03-21
3
966 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

617 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