Click here to Skip to main content
15,441,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
<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:
C#
<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)
        {
        ////    //Page logindetails = Page.PreviousPage;
        //    //if (logindetails != null)
        //    //{
        //    //    TextBox usernametxt = (TextBox)logindetails.FindControl("txtuser");
        //    //    String username = usernametxt.Text;

        //    //    TextBox pwdtxt = (TextBox)logindetails.FindControl("txtpwd");
        //    //    String password = pwdtxt.Text;
        //    //}
            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 btncancel_Click(object sender, EventArgs e)
        //{
            

        //    if (txtmemid.Text != "")
        //        txtmemid.Text = "";
        //    if (txtcardid.Text != "")
        //        txtcardid.Text = "";
        //    if (txtname.Text != "")
        //        txtname.Text = "";
        //    if (txtdate.Text != "")
        //        txtdate.Text = "";
        //    if (txtopenbal.Text != "")
        //        txtopenbal.Text = "";
        //    if (txtphone.Text != "")
        //        txtphone.Text = "";
        //    if (txtaddress.Text != "")
        //        txtaddress.Text = "";
        //    if (txtpwd.Text != "")
        //        txtpwd.Text = "";
        //    if (txtconfirmpwd.Text != "")
        //        txtconfirmpwd.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();

                }//connection
            }//if
            //else
            //{
            //    Response.Write("<script type='text/javascript'>");
            //    Response.Write("alert('PLEASE ENTER EITHER MEMBER ID or CARD ID');");
            //    Response.Write("</script>");


            //}
        }

        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.
Posted

1 solution

Well I might suggest a few changes to the btndok_Click

C#
protected void btndok_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtdmemid.Text) || 
                !string.IsNullOrEmpty(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();

                }
            }
        }


I also think it could be dangerous to be using an 'OR' in your delete SQL, you should be deleting by one or the other, you could delete unintended things.
 
Share this answer
 
Comments
Member 10263519 22-Jan-14 23:35pm     CRLF
still same problem, with out entering any data into textboxes ,if i click OK ,then popup is showing "do You want to delete." if i doesn't enter any data , that should give a message as enter data for memberid or card id. may be i need to write server side popup control instead of client side in button click,how to solve it.
bowlturner 23-Jan-14 8:52am    
I took a closer look, you are calling the pop up every time, not just when there is data in the textboxes.
Member 10263519 24-Jan-14 4:04am    
plz give me solution , how to solve it. am struggling a lot with this issue.
Member 10263519 24-Jan-14 7:41am    
How to check whether the textboxes having data or not in javascript. how to get the value of textboxes(which are in ajaxtabcontrol toolkit tabs) in javascript

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900