ASP.NET WebForms: How to fetch and display calendar events in a popup without 401 errors?
02:18 19 Dec 2025

I am building a calendar with a reminder popup in ASP.NET WebForms. I want to fetch events from a SQL Server database and display them when a user clicks a date.

Currently, I tried using a Shared WebMethod with EnablePageMethods="true" like this:

 _
Public Shared Function GetEvents(dateStr As String) As String
    ' SQL fetch logic
End Function

And call it via jQuery AJAX:

$.ajax({
    type: "POST",
    url: "Cal.aspx/GetEvents",
    data: JSON.stringify({ dateStr: dateStr }),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(response) { ... }
});

Problems I face:

  • When calling the WebMethod, I get a 401 Unauthorized error.

  • Using EnablePageMethods and Shared WebMethod seems tricky with authentication.

What I want:

  • Fetch events from the database and show them in a popup for a selected date.

  • Avoid 401 errors and make it simple to work with jQuery/AJAX.

What I’ve tried:

  • Enabling EnablePageMethods="true"

  • Using Shared WebMethods

  • Attempting anonymous access in IIS

Question:
What is the best way to fetch and display data in a calendar popup in WebForms

javascript ajax vb.net webforms http-status-code-401