title: How to use ScriptManager.RegisterStartupScript in a WebMethod in asp.net?
body: <p>I have a condition where i need to call a jquery function using a webmethod as below:</p>
  
  <pre><code>[WebMethod]
  public static void BindData(String Site)
  {
      String HTML = "";
      Int32 i = 1;
      DataTable dt = new DataTable();
      dt = obj.GetAll(objprop);
      if (dt.Rows[0]["UserId"].ToString() != "0")
      {
          foreach (DataRow item in dt.Rows)
          {
              string Email = Bal.Common.Decryptdata(item["Email"].ToString());
              string SentInvitation = item["SentInvitation"].ToString();
  
              SentInvitation = SentInvitation.ToString() == "1" ? "Already Invited" : "";
              if (i % 2 == 0)
                  HTML += "&lt;div class=~other_wish_row2~&gt;&lt;div class=~friend_list_box1~&gt;&lt;input type=~checkbox~ class=~chkEmail~ id=~chkId^" + i + "~/&gt;&lt;/div&gt;&lt;div class=~friend_list_box2~&gt;&lt;p&gt;&lt;label id=~lbl" + i + "~&gt;" + Email.ToString() + "&lt;/label&gt;&lt;label class=~SentInvitationLbl~ id=~lblSentInvitation" + i + "~&gt;" + SentInvitation + "&lt;/label&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class=~friend_list_box3~&gt;&lt;/div&gt;&lt;div class=~clear~&gt;&lt;/div&gt;&lt;/div&gt;";
              else
                  HTML += "&lt;div class=~other_wish_row3~&gt;&lt;div class=~friend_list_box1~&gt;&lt;input type=~checkbox~ class=~chkEmail~ id=~chkId^" + i + "~/&gt;&lt;/div&gt;&lt;div class=~friend_list_box2~&gt;&lt;p&gt;&lt;label id=~lbl" + i + "~&gt;" + Email.ToString() + "&lt;/label&gt;&lt;label class=~SentInvitationLbl~ id=~lblSentInvitation" + i + "~&gt;" + SentInvitation + "&lt;/label&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class=~friend_list_box3~&gt;&lt;/div&gt;&lt;div class=~clear~&gt;&lt;/div&gt;&lt;/div&gt;";
  
              i = i + 1;
          }
          ScriptManager.RegisterStartupScript((Page)(HttpContext.Current.Handler), typeof(Page), "hdrEmpty1", "Test('" + HTML + "');", true); return;
      }
      else
      {
  
      }
  }
  </code></pre>
  
  <p>Jquery Code is:</p>
  
  <pre><code>function Test(data) {
     alert('hi');
  }
  
  function Binddata(SocialSite) {
  
  $.ajax({
      type: "POST",
      url: "InviteFriends.aspx/BindData",
      data: "{SocialSite:'" + SocialSite + "'}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (msg) {
  
      }
   });
  }
  </code></pre>
  
  <p>I am not able to fire <strong>Test()</strong>, please help to resolve this.</p>