Question: The main page has a button labeled AJAX Reverse. Please add the required JavaScript code to $('#btnAJAXReverse').click(). You are encouraged to use the code from
- The main page has a button labeled AJAX Reverse. Please add the required JavaScript code to $('#btnAJAXReverse').click(). You are encouraged to use the code from $('#btnAJAXGet').click() as a template.
- Make an AJAX call to the WebMethod Reverse on the web page GetReply.aspx
- Display the returned value in lblLoginResult Note: the string will be returned unchanged until you add code to the C# WebMethod, which you do in the next step of this lab.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%-- Based heavily on the sample project from http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/ --%>
AJAX Request to another page, with data
User names: nana, student, and amin are valid.
All others are invalid.
- There is a WebMethod called Reverse in GetReply.aspx.cs. Some of the code has already been filled in for you. Please add C# code so the WebMethod:
- Accepts a string as a parameter from the web page.
- Reverses the string.
- Return the reversed string to the web page.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Services;
public partial class GetReply : System.Web.UI.Page { [WebMethod] public static string Login(string userName) { var acceptedNames = new List {"nana", "admin", "student"};
if (acceptedNames.Contains(userName) ){ return "Accepted"; } else { return "Denied"; } }
[WebMethod] public static string Reverse(string strInput) { string strReturnVal;
// Replace this with code to reverse the string strReturnVal = strInput;
return strReturnVal; }
}
