0

I have a javascript function for ShowDocument in which I need to call a code behind function My Js FUNCTION is as follows:

function showDocument(_id) 
{
    PageMethods.ShowDocument();
}

Codebehind:

[System.Web.Services.WebMethod]
public static void ShowDocument()
{
    byte[] bytes;
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        con.Open();
        using (SqlCommand com = new SqlCommand("SELECT Data FROM FileUploader2", con))
        {
            using (SqlDataReader reader = com.ExecuteReader())
            {
                if (reader.Read())
                {
                    bytes = (byte[])reader["Data"];
                }
            }
        }
    }
}

I have added EnablePageMethods= true in my aspx as well.

But when I debug, it triggers my ShowDocument function but does not go inside my code behind function. It just skips it. What am i doing wrong?

Unknown
  • 145
  • 2
  • 11
  • Did you mean you want to call your `web method` from `JavaScript function`? what's your back end method `URL` – Md Farid Uddin Kiron Feb 14 '20 at 10:18
  • Yes I want to call my c# from javascript. For which I followed this link https://stackoverflow.com/questions/7089760/how-to-call-an-asp-net-c-sharp-method-using-javascript .My function gets trigerred as well but then it skips to the end. – Unknown Feb 14 '20 at 10:20
  • Make sure you have specified the ScriptManage Id. – Abdul Jabbar Feb 14 '20 at 10:26
  • I have added this at the top of aspx where do I have to specify ID="ScriptManager1" ? – Unknown Feb 14 '20 at 10:28

0 Answers0