i have a web page having ajaxtabcontrol (add,delete,edit...)
in delete tab i need to enter memberid ,cardid then hit OK button,it should give popup confirmation,if i hit OK that record should be deleted from database(MYSQL)and textboxes should be cleared.
here is the code for webpage design:
<pre lang="c#"><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="Online_Billing_System.Admin" %>
<%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" tagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Admin</title>
<script type="text/javascript">
function DeleteItem() {
if (confirm("Are you sure you want to delete ...?")) {
return true;
}
return false;
}
</script>
<style type="text/css">
.style1
{
width: 151px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="scriptmanager1" runat="server">
</ajax:ToolkitScriptManager>
<div style=" width:89%">
<ajax:TabContainer ID="adminTabContainer" runat="server" ActiveTabIndex="2">
<ajax:TabPanel ID="tbpnladd" runat="server" ><HeaderTemplate>
Add Member
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="AddMem" runat="server" Width="738px">
<table align="center"
style="width: 651px"><tr>
<td></td><td align="right" ></td>
<td align="center">Add Member </td></tr>
<tr><td></td><td align="right" >Member ID: </td><td>
<asp:TextBox ID="txtmemid" runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage=" Enter Member ID " ControlToValidate="txtmemid"
ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td></tr>
<tr><td></td><td align="right" >Card ID: </td><td>
<asp:TextBox ID="txtcardid" runat="server" ></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Enter Card ID" ControlToValidate="txtcardid" ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td></tr>
<tr><td></td><td align="right">Name: </td><td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Enter Name" ControlToValidate="txtname" ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td></tr>
<tr><td></td><td align="right">Date Of Membership: </td><td>
<asp:TextBox ID="txtdate" runat="server"
></asp:TextBox> </td><td>
<ajax:CalendarExtender ID="calendar1"
TargetControlID="txtdate" runat="server" PopupButtonID="calendar"
Format="yyyy-MM-dd" Enabled="True"></ajax:CalendarExtender></td>
<td class="style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Enter Date Of Membership" ControlToValidate="txtdate" ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td></tr>
<tr><td></td><td align="right">Opening Balance: </td><td>
<asp:TextBox ID="txtopenbal" runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Enter Opening Balance" ControlToValidate="txtopenbal" ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td></tr>
<tr><td></td><td align="right" >Phone No: </td><td>
<asp:TextBox ID="txtphone" runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Enter Phone No" ControlToValidate="txtphone" ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td></tr>
<tr><td></td><td align="right" >Address: </td><td align="left"><asp:TextBox ID="txtaddress" runat="server"></asp:TextBox></td><td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="Enter Address" ControlToValidate="txtaddress" ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td></tr>
<tr><td></td><td align="right">Password:</td><td align="left">
<asp:TextBox ID="txtpwd" runat="server" TextMode="Password"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Enter Password" ControlToValidate="txtpwd" ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td></tr>
<tr><td></td><td align="right">Confirm Password</td><td align="left">
<asp:TextBox ID="txtconfirmpwd" runat="server" TextMode="Password"></asp:TextBox></td><td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="Enter Confirm Password" ControlToValidate="txtconfirmpwd" ForeColor="Red" ValidationGroup="addGroup"></asp:RequiredFieldValidator></td>
<td><asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtpwd" ControlToValidate="txtconfirmpwd" ErrorMessage="Passwords Don't Match" ForeColor="Red" ValidationGroup="addGroup"></asp:CompareValidator></td></tr>
<tr><td></td>
<td></td><td align="left" >
<asp:Button ID="btnok" runat="server" Text="OK" onclick="btnok_Click" ValidationGroup="addGroup"/>
<asp:Button ID="btncancel" runat="server" Text="Cancel"
OnClientClick="this.form.reset();return false;" ValidationGroup="addGroup"/></td></tr></table></asp:Panel>
</ContentTemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="tbpnledit" runat="server" ><HeaderTemplate>
Edit Member
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="EditMem" runat="server" Width="570px">
<table align="center">
<tr>
<td align="right" colspan="2" ></td>
<td>
Edit Member </td></tr>
<tr><td align="right" colspan="2">Member ID: </td>
<td><asp:TextBox ID="txtememid" runat="server"></asp:TextBox> </td></tr>
<tr><td align="right" colspan="2">Card ID: </td>
<td>
<asp:TextBox ID="txtecardid" runat="server" Width="112px"></asp:TextBox> </td></tr>
<tr> <td>
<asp:Button ID="btneok" runat="server" Text="OK"
OnClick="btneok_Click" Font-Bold="True" Font-Names="Times New Roman"
Width="87px"/> </td><td>
<asp:Button ID="btnecancel" runat="server" Text="Cancel"
Width="96px" OnClientClick="this.form.reset();return false;"
/></td></tr></table></asp:Panel>
</ContentTemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="tbpnldelete" runat="server" ><HeaderTemplate>
Delete Member
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="DeleteMem" runat="server" Width="476px">
<table align="center">
<tr>
<td></td>
<td align="right" ></td>
<td class="style1">Delete Member </td></tr>
<tr><td></td><td align="right">Member ID: </td><td class="style1">
<asp:TextBox ID="txtdmemid" runat="server" Height="21px" Width="112px"
></asp:TextBox> </td> <td></td></tr>
<tr><td></td><td align="right">Card ID: </td><td class="style1">
<asp:TextBox ID="txtdcardid" runat="server"
></asp:TextBox> </td></tr>
<tr><td></td><td align="right">
<asp:Button ID="btndok" runat="server" Text="OK" OnClick="btndok_Click" onclientclick="return DeleteItem()" /> </td>
<td class="style1">
<asp:Button ID="btndcancel" runat="server" Text="Cancel"
onclick="btndcancel_Click" OnClientClick="this.form.reset();return false;" /> </td></tr></table></asp:Panel>
</ContentTemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="tbpnlview" runat="server" ><HeaderTemplate>
View Member
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="ViewMem" runat="server" Width="477px">
<table align="center">
<tr>
<td></td>
<td align="right" ></td>
<td class="style1">View Member </td></tr>
<tr><td></td><td align="right">Member ID: </td><td class="style1"><asp:TextBox ID="txtvmemid" runat="server"></asp:TextBox> </td></tr>
<tr><td></td><td align="right">Card ID: </td><td class="style1"><asp:TextBox ID="txtvcardid" runat="server"></asp:TextBox> </td></tr>
<tr><td></td><td align="right">
<asp:Button ID="btnvok" runat="server" Text="OK" onclick="btnvok_Click" /> </td><td class="style1">
<asp:Button ID="btnvcancel" runat="server" Text="Cancel" OnClientClick="this.form.reset();return false;"/> </td></tr></table></asp:Panel>
</ContentTemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="tbpnlviewall" runat="server" ><HeaderTemplate>
View All
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="ViewAllMem" runat="server">
<asp:GridView ID="viewallGridview" runat="server">
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</ajax:TabPanel>
<ajax:TabPanel ID="tbpnlsetting" runat="server" ><HeaderTemplate>
Settings
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="settings" runat="server" Width="530px">
<table align="center">
<tr>
<td></td>
<td align="right" ></td>
<td class="style1">Change Password </td></tr>
<tr><td></td><td align="right">Current Password: </td><td class="style1">
<asp:TextBox ID="txtcupwd" runat="server" Height="21px" Width="112px"></asp:TextBox> </td></tr>
<tr><td></td><td align="right">New password: </td><td class="style1"><asp:TextBox ID="txtnewpwd" runat="server"></asp:TextBox> </td></tr>
<tr><td></td><td align="right">Reenter New password: </td><td class="style1"><asp:TextBox ID="txtreenterpwd" runat="server"></asp:TextBox> </td></tr>
<tr><td></td><td align="right">
<asp:Button ID="btnsettingsok" runat="server" Text="OK" OnClick="btnsettingsok_Click" /> </td><td class="style1">
<asp:Button ID="btnsettingscancel" runat="server" Text="Cancel"
OnClientClick="this.form.reset();return false;" /> </td></tr></table></asp:Panel>
</ContentTemplate>
</ajax:TabPanel>
</ajax:TabContainer>
</div>
</form>
</body>
</html>
and codebehind is:
<pre lang="c#">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using MySql.Data.MySqlClient;
namespace Online_Billing_System
{
public partial class Admin : System.Web.UI.Page
{
String ConnectionString = WebConfigurationManager.ConnectionStrings["myConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
string s = Request.QueryString["UserName"];
String x = Request.QueryString["Password"];
}
protected void btnok_Click(object sender, EventArgs e)
{
using (MySqlConnection con = new MySqlConnection(ConnectionString))
{
String query = "insert into admin(member_id,card_id,name,date_of_membership,opening_balance,phone_number,address,password,confirm_password) values(@memberid,@cardid,@name,@date,@balance,@phone,@address,@pwd,@confirmpwd)";
MySqlCommand command = new MySqlCommand(query,con);
command.Parameters.AddWithValue("@memberid", txtmemid.Text);
command.Parameters.AddWithValue("@cardid", txtcardid.Text);
command.Parameters.AddWithValue("@name", txtname.Text);
command.Parameters.AddWithValue("@date", txtdate.Text);
command.Parameters.AddWithValue("@balance", txtopenbal.Text);
command.Parameters.AddWithValue("@phone", txtphone.Text);
command.Parameters.AddWithValue("@address", txtaddress.Text);
command.Parameters.AddWithValue("@pwd", txtpwd.Text);
command.Parameters.AddWithValue("@confirmpwd", txtconfirmpwd.Text);
con.Open();
command.ExecuteNonQuery();
}
txtmemid.Text = "";
txtcardid.Text = "";
txtname.Text = "";
txtdate.Text = "";
txtopenbal.Text = "";
txtphone.Text = "";
txtaddress.Text = "";
}
protected void btneok_Click(object sender, EventArgs e)
{
if (txtememid.Text != "" || txtecardid.Text != "")
Response.Redirect("~/EditUser.aspx?memberid=" + txtememid.Text.Replace("&", "%26") +
"&cardid=" + txtecardid.Text.Replace("&", "%26"));
else
{
Response.Write("<script type='text/javascript'>");
Response.Write("alert('PLEASE ENTER EITHER MEMBER ID or CARD ID');");
Response.Write("</script>");
}
}
protected void btndok_Click(object sender, EventArgs e)
{
if (txtdmemid.Text != "" || txtdcardid.Text != "")
{
using (MySqlConnection con = new MySqlConnection(ConnectionString))
{
String query = "delete from admin where member_id=@memid OR card_id=@card";
MySqlCommand command = new MySqlCommand(query, con);
command.Parameters.AddWithValue("@memid",txtdmemid.Text);
command.Parameters.AddWithValue("@card", txtdcardid.Text);
con.Open();
command.ExecuteNonQuery();
}
}
}
protected void btndcancel_Click(object sender, EventArgs e)
{
}
protected void btnvok_Click(object sender, EventArgs e)
{
if (txtvmemid.Text != "" || txtvcardid.Text != "")
{
Response.Redirect("~/View.aspx?memberid=" + txtememid.Text.Replace("&", "%26") +
"&cardid=" + txtecardid.Text.Replace("&", "%26"));
}
else {
Response.Write("<script type='text/javascript'>");
Response.Write("alert('PLEASE ENTER EITHER MEMBER ID or CARD ID');");
Response.Write("</script>");
}
}
protected void btnsettingsok_Click(object sender, EventArgs e)
{
using (MySqlConnection con = new MySqlConnection(ConnectionString))
{
String query = "select password from admin";
MySqlCommand command = new MySqlCommand(query,con);
con.Open();
using (MySqlDataReader rdr = command.ExecuteReader())
{
while (rdr.Read())
{
String currentpwd = txtcupwd.Text;
String dbpwd = rdr["password"].ToString();
if (currentpwd.Equals(dbpwd))
{
String query2 = "update admin set password=@pwd";
MySqlCommand com = new MySqlCommand(query2, con);
com.Parameters.AddWithValue("@pwd", txtcupwd.Text);
com.ExecuteNonQuery();
}
else {
Response.Write("<script type='text/javascript'>");
Response.Write("alert('Please Enter Correct Password');");
Response.Write("</script>");
}
}
}
}
}
}
}
here the problem is without entering any value in teaxtbox ,if i hit OK it's deleting record.