Click here to Skip to main content
15,906,766 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i have a function!


i want to call it from code behind in asp.net please tell me how to do it Thanks in advance

What I have tried:

$(document).ready(function() {
  $(".tstInfo").on("click",function(){
       $.toast({
        heading: 'Welcome to my Elite admin',
        text: 'Use the predefined ones, or specify a custom position object.',
        position: 'top-right',
        loaderBg:'#ff6849',
        icon: 'info',
        hideAfter: 3000, 
        stack: 6
      });

 }); });
Posted
Updated 16-Mar-18 1:24am

1 solution

You can't call js from code-behind because js only exists in the browser and your code-behind is generating the response to send to the browser so the js only exists when your server code has finished. What you *can* do is add js to the output that calls the js you want to execute when the browser loads. You can use Page.RegisterStartupScript Method (String, String) (System.Web.UI)[^] to do that.

Alternatively you could google "asp.net call javascript from code behind" where you will see this is a very frequently asked question and you'll doubtless find more examples.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900