Search code examples
c#jqueryajaxwebformsasp.net-3.5

ASP.NET Response Redirect of URL Error; from static method


I am working on ASP.NET 3.5 App. I have $ajax jQuery function calling code-behind method with sending staff ID.

I want Response.Redirect to open from this method but getting following error

enter image description here

$ajax function calling code-behind method

$.ajax({
       url: 'AddUserInRole.aspx/GetRolesListFilteredByStaff_NotIn',
       type: "POST",
       data: JSON.stringify({ GivenStaffID: selectStaffIDToAddRole }),
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (response) {
               alert(response.d);
        },
       failure: function (response) {
                alert(response.d);
                   }
       }).done(function (response) {
                   //
  });

Code-Behind Method

[WebMethod]
private static void GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
 {
    Response.Redirect("/SelectRoleForStaff.aspx?staffID='GivenStaffID'");            
 }

my 2nd question is how to read staffID from url in new upload page

Update Partial Answer

I have managed to call the require method but its not redirecting page...

  [WebMethod]
  public static void GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
    {
        HttpContext.Current.Response.Redirect("/SelectRoleForStaff.aspx?staffID="+GivenStaffID);            
    }

Solution

  • Update your method to return the url to redirect like:

    [WebMethod]
    public static string GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
    {
       return "SelectRoleForStaff.aspx?staffID=" + GivenStaffID;
    }
    

    And in your ajax success do this:

    success: function (response) {
                   window.location = response;
                   // OR
                   window.location = response.d;
            },