In this post, we want to discuss a nice function to Call the JavaScript function from code behind in C#. Before we get started, if you want to know about required field validation with jQuery, please go through the following article: Simple Required Field Validation on jQuery.
Many times we come across situations where we need to call jQuery functions from code-behind. This can be achieved by registering the ClientScript block. Let’s take a look at an example.
JavaScript function :
1 2 3 4 5 6 7 |
<script type="text/javascript"> function WelcomeUser(username) { alert("Welcome::" + username); } </script> |
Code-behind :
1 2 3 4 5 6 |
protected void Page_Load(object sender, EventArgs e) { ClientScript.RegisterStartupScript(GetType(),"hwa", "WelcomeUser('VJ');", true); } |
Call JavaScript function from code behind in C#
The article was published on August 6, 2014 @ 12:13 PM
Leave a Comment