ASP.NET Tutorial : How To Call JS Function In C# ?

Leave a Comment

Call JS Function In C#

With a Web application, javascript and jquery functions play an important role when we want to send values to the server side.

 This article will discuss in the Web application how calls JavaScript/Jquery Functions on the server side.

For this, we must create WebForms in Visual Studio, which is supported by .Net framework 4.5.

We can call the javascript function in c# by using the RegisterStartupScript method in ScriptManager and ClientScript class from the System. Web. UI namespace. But both classes can be accessed from WebForms only, not by normal classes, which means .aspx pages.

By using ScriptManager class,

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),
                      "loadJSFunction();", true);

By using ClientScript class,

            (GetType(), Guid.NewGuid().ToString(), "loadJSFunction();", true);

By using param,

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),
                      "loadJSFuncParam('" + param + "');", true);

JS Function,

<script type="text/javascript">
function loadJSFunction() {
    alert("Hi Load JS")
function loadJSFuncParam(param) {

Windows Hosting Recommendation

HostForLIFEASP.NET receives Spotlight standing advantage award for providing recommended, cheap and fast ecommerce Hosting including the latest Magento. From the leading technology company, Microsoft. All the servers are equipped with the newest Windows Server 2012 R2, SQL Server 2014, ASP.NET 7.0.4, ASP.NET MVC 6.0, Silverlight 5, WebMatrix and Visual Studio Lightswitch. Security and performance are at the core of their Magento hosting operations to confirm every website and/or application hosted on their servers is highly secured and performs at optimum level. mutually of the European ASP.NET hosting suppliers, HostForLIFE guarantees 99.9% uptime and fast loading speed. From €3.49/month , HostForLIFE provides you with unlimited disk space, unlimited domains, unlimited bandwidth,etc, for your website hosting needs.
Next PostNewer Post Previous PostOlder Post Home


Post a Comment