Solved

How to Trigger JQuery function from code behind

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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

759 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