Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);            
    }
like image 781
K.Z Avatar asked Jan 25 '26 18:01

K.Z


1 Answers

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;
        },
like image 126
Oluwafemi Avatar answered Jan 28 '26 07:01

Oluwafemi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!