In this post, we want to discuss about a nice function to Call 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 ClientScript block. Let’s take a look by 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); } |
Leave a Comment