Search code examples
jqueryasp.netfunctioncode-behind

Why more than one JQuery functions are not Calling from Codebehind


I am trying to call two simple functions from my asp.net codebehind and only one function is working and not the other.

Here are my functions:

  function Clear() {
                     alert('Cleared');
                 }

  function Add() {
                     alert('Added');
                 }

I have a simple button click event as shown below:

 Public Sub btnProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProcess.Click

    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "Script", "Clear();", True)
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "Script", "Add();", True)

 End Sub

If I comment out one function the other is working and the vice-versa but not both at a time.


Solution

  • The docs for RegisterClientScriptBlock state that the script key have to be distinct, otherwise they are seen as duplicates (which is what is happening in your case).