Monday, June 30, 2014

JSON - JavaScript Object Notation

Combination of Showing MessageBox and select yes to backend.
  
JSON - Mostly use when UI to Backend
  <script type="text/javascript">
        function RedirectToEdit(userID) {
            $.ajax({
                type: "post",
                url: "Client.aspx/RedirectToEdit",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: '{"userID":"' + userID + '"}',
                success: function (result) {
                    window.parent.location.href = "Client.aspx?action=edit";
                },
                error: function (xhr, status, error) {
                    alert("Failed to go Edit Page.")
                }
            });
        }

JAVASCRIPT
        function DisplayClient() {
            var x = confirm('This User ID already exist. Press "Ok" to Edit Page.');
            if (x == true) {
                $('INPUT[id*=btnRedirectEdit]').click();
                var userID = $('INPUT[id*=txtUserID]').val();
                RedirectToEdit(userID);
            }
        }

    </script>


C# Backend
[System.Web.Services.WebMethod]
public static bool RedirectToEdit(string userID)
{
            ClientController clientController = new ClientController();
            UserSession upc = new UserSession();

            upc.SessionSelectedClientID = userID;
            upc.SessionSelectedModID = "*Client.aspx?action=edit";
            return true;
}

No comments:

Post a Comment