3

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);            
    }
5
  • Is this an .asmx fille where the exception occurs? Commented Sep 24, 2015 at 12:23
  • have a look in my question under Update Partial Answer .... Commented Sep 24, 2015 at 12:31
  • many thanks........... Commented Sep 24, 2015 at 12:31
  • ok let me rephrase that. Is the file you've got that method a aspx or asmx file? Commented Sep 24, 2015 at 12:32
  • Let us continue this discussion in chat. Commented Sep 24, 2015 at 12:49

1 Answer 1

8

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;
        },
Sign up to request clarification or add additional context in comments.

1 Comment

In my case the page is having a postback and javascript function is not able to run

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.