Call JavaScript function from c# Code behind (Server Side) in Asp.net

In this asp .net tutorial we will learn how to call JavaScript function from asp .net code behind. We will cover following scenarios in this tutorial: Call JavaScript function from asp .net code behind. Call JavaScript function from asp .net code behind and pass values to the function. Create functions in JavaScript

    

Explanation: First function "showAlert" will display alert message box and second function "sumValues" will take 2 arguments and displays their sum in alert box.

Call JavaScript function without arguments.

 

 protected void btnShowAlert_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, GetType(), "AnyValue", "showAlert();", true);
    }

Call JavaScript function with arguments.

 

 protected void btnPassValues_Click(object sender, EventArgs e)
    {
        int a = 10;
        int b = 20;
        ScriptManager.RegisterStartupScript(this, GetType(), "AnyValue", "sumValues(" + a + "," + b + ");", true);
    }

Final Output

call javascript function from asp net code behind and server side

Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
5 + 1 =
 

About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2024 CodingFusion
50+ C# Programs for beginners to practice