Solved

How to Trigger JQuery function from code behind

Posted on 2011-03-21
3
939 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
Comment Utility
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
Comment Utility

// 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
Comment Utility
Thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now