hi everyone i'm learn crud using jquery ajax in asp.net webform. i'm get problem with the update and delete function, the insert function working properly. why the update and delete not working.
any help would be appriciate.
this webform the crud_ajax.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="crud_ajax.aspx.cs" Inherits="api" Debug="true" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <style type="text/css">
- body
- {
- font-family: Arial;
- font-size: 10pt;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <div align="center">
- <table border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td>ID:
- </td>
- <td>
- <asp:TextBox ID="txtID" runat="server" Text="" />
- </td>
- </tr>
- <tr>
- <td>Username:
- </td>
- <td>
- <asp:TextBox ID="txtUsername" runat="server" Text="" />
- </td>
- </tr>
- <tr>
- <td>Password:
- </td>
- <td>
- <asp:TextBox ID="txtPassword" runat="server" />
- </td>
- </tr>
- <tr>
- <td></td>
- <td>
- <asp:Button ID="btnSave" OnClick="btnSave_Click" Text="Save" runat="server" />
- <asp:Button ID="btnUpdate" Text="Update" OnClick="btnUpdate_Click" runat="server" />
- <asp:Button ID="btnHapus" Text="Hapus" OnClick="btnHapus_Click" runat="server" />
- </td>
- </tr>
- </table>
- <hr />
- <asp:GridView ID="gvUsers" runat="server" AutoGenerateColumns="false" HeaderStyle-BackColor="#3AC0F2"
- HeaderStyle-ForeColor="White" RowStyle-BackColor="#A1DCF2">
- <Columns>
- <asp:BoundField DataField="user_name" HeaderText="Username" />
- <asp:BoundField DataField="password" HeaderText="Password" />
- </Columns>
- </asp:GridView>
- </div>
- </form>
- <script type="text/javascript" src="assets/jquery.js"></script>
- <script type="text/javascript" src="assets/json2.js"></script>
- <script type="text/javascript">
- $("[id*=btnSave]").click(function () {
- {
- var user = {};
- user.Username = $("[id*=txtUsername]").val();
- user.Password = $("[id*=txtPassword]").val();
- $.ajax({
- type: "POST",
- url: "crud_ajax.aspx/SaveUser",
- data: '{user: ' + JSON.stringify(user) + '}',
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (response) {
- alert("User has been Update successfully.")
- window.location.reload();
- }
- })
- return false;
- }
- });
- </script>
- <script type="text/javascript">
- $("[id*=btnUpdate]").click(function () {
- var _UpdateUser = {};
- _UpdateUser.ID = $("[id*=txtID]").val();
- _UpdateUser.Username = $("[id*=txtUsername]").val();
- _UpdateUser.Password = $("[id*=txtPassword]").val();
- $.ajax({
- type: "POST",
- url: "crud_ajax.aspx/UpdateUser",
- data: '{_UpdateUser: ' + JSON.stringify(_UpdateUser) + '}',
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (response) {
- alert("User has been Update successfully.")
- window.location.reload();
- });
- return false;
- });
- </script>
- <script type="text/javascript">
- $("[id*=btnHapus]").click(function (id) {
- var _HapusUser = _HapusUser.id;
- $.ajax({
- type: "POST",
- url: "crud_ajax.aspx/HapusUser",
- data: "{'id':'" + idd + "'}",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (response) {
- alert("User has been Delete successfully.")
- window.location.reload();
- }
- });
- return false;
- });
- </script>
- </body>
- </html>
this is code bihind