2

How register (call) jQuery function from asp.net usercontrol from codebehind file?

Nick Craver
  • 610,884
  • 134
  • 1,288
  • 1,151
Bendar
  • 21
  • 5

1 Answers1

4

You can use ClientScriptManager.RegisterStartupScript(), for example:

var script = "$(function() { $('#message').fadeIn(); });";
Page.ClientScript.RegisterStartupScript(GetType(), "keyHere", script, true);

This gets rendered to the page as:

<script type="text/javascript">
  $(function() { $('#message').fadeIn(); });
</script>

The script is just any JavaScript, nothing special about jQuery, just put in there whatever you would manually put in the page, since that's how it ends up.

Nick Craver
  • 610,884
  • 134
  • 1,288
  • 1,151
  • 1
    @Bendar - Welcome! And welcome to SO! Be sure to accept answers, mingle with the natives and enjoy your stay :) – Nick Craver Jun 14 '10 at 21:45