Want a free Ebook & latest Update Subscribe Now
  [email protected]      beta
Donate

How to call javascript function from code behind server side Asp.net C#

Overview: Calling Javascript funtion from server side .i.e code behind in Asp.net C#.This article explains how to call a JavaScript function from server side (code behind) in Asp.net C# . First we add page and write a JavaScript function on our .aspx page, here default.aspx is our newly added  page.

Code : Add a JavaScript function on default.aspx page under head tag.

//*
<script type="text/javascript" language="javascript">
	function helloWorld(){
	   alert("welcome to startcoding.in");	
	}
</script>
//*

 

 Server side : using below given code we able to call JavaScript function from server-side.

//*
ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);
//*

 

as our JavaScriptript function name as helloWorld() so our final code would be like as given below

//*
ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:helloWorld(); ", true);
//*

 

If you have  used Asp.net UpdatePanel in your Design page (.aspx page ) then the code will be like

//*
ScriptManager.RegisterStartupScript(GetType(), "Javascript", "javascript:FUNCTIONNAME(); ", true);
//as our javascript function name as helloWorld() so we write this code as
ScriptManager.RegisterStartupScript(GetType(), "Javascript", "javascript:helloWorld(); ", true);
//*

 

Share:    
Satinder Singh

Hi all, am Founder and Author of Codepedia.info, also atypical polyglot programmer from Bombay, India. I have a passion to create, solve, and deploy software applications.
       ForEach ( minute in MyLife ) { myExperience++ ; }



Post Comment


Your email address will not be published. Required fields are marked *