2

I want to do JavaScript alert in static method server side code in asp.net with C#. I tried many ways, but it's not working.

For example, I tried

[WebMethod]
public static void EntrySave(string schoolName)
{
      Response.Write("<script>alert('Hello');</script>");
}

and

[WebMethod]
public static void EntrySave(string schoolName)
{
      ScriptManager.RegisterStartupScript(this, GetType(), "showalert", 
       "alert('Only alert Message');", true);
}

and many more. But it's not showing alert in webstatic method.

halfer
  • 19,824
  • 17
  • 99
  • 186
s.k.Soni
  • 1,139
  • 1
  • 19
  • 37

2 Answers2

1

Some examples may help you

https://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx

https://www.aspsnippets.com/Articles/Send-and-receive-JavaScript-Array-to-Web-Service-Web-Method-using-ASP.Net-AJAX.aspx

Response.Write() in WebService

Hardik Leuwa
  • 3,282
  • 3
  • 14
  • 28
  • 1
    https://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx. This url is work for me. Thank You. @Hardik Leuwa. – s.k.Soni Jul 04 '17 at 07:21
0

you can use

    [WebMethod]
    public static void EntrySave(string schoolName)
    {Response.Write("alert('Hello')");
}

More can be found here

Bhawna Jain
  • 709
  • 10
  • 27
  • Mis Bhawna it is not working as per I tell you previously only. Infact at Response it is showing red underline. – s.k.Soni Jul 04 '17 at 07:05
  • can you attach a screen shot of error you are getting in your answer.? – Bhawna Jain Jul 04 '17 at 07:16
  • got the solution. Thank You. Mis Bhawna for trying to solve my issue. – s.k.Soni Jul 04 '17 at 07:21
  • Hy Mis Bhawna please review this link......"https://stackoverflow.com/questions/44992714/undefined-coming-when-bind-gridview-using-ajax-in-c-sharp/44993886#44993886" – s.k.Soni Jul 10 '17 at 05:44