Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

i have delete tab , in that i need to enter either memberid or cardid then hit OK.
when i hit OK button then popup should come for confirmation (OK,Cancel),if press OK ,need to delete record and clear the textbox.

my problem is:
with out entering any in textboxes ,click OK button then it's giving popup,
how to solve it.
here is the code for Delete tab:
C#
<pre lang="c#"><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></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>

and ok button code behind is:
C#
<pre lang="c#"> 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>");


            //}
        }
Posted
Comments
Tejas Vaishnav 22-Jan-14 3:42am    
what is your javascript code you have write in "DeleteItem()"
Member 10263519 22-Jan-14 4:12am    
<script type="text/javascript">
function DeleteItem() {
if (confirm("Are you sure you want to delete ...?")) {
return true;
}
return false;
}
</script>

You can try with Requiredfieldvalidator control.
This link may be usefull
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator(v=vs.110).aspx[^]
 
Share this answer
 
javascript code:

XML
<script language="javascript" type="text/javascript">
        function ConfirmOnDelete(SIMCODE) {
            if (confirm("Are you SURE you want to Delete") == true) {
                window.location = "del.aspx?SIMCODE=" + SIMCODE + "&DOIF=" + 7;
                return true;
            }

The javascriopt code is redirecting me to the del.aspx page with query string. where i'm performing delete function, u can c delete function after button code.

button code:

<button id="btndel" value="Delete" class="btn btn-danger" placeholder="Delete" onclick="ConfirmOnDelete('<%# Eval("MobileNo") %>')">Del
                                                           </button>


Delete function on del.aspx page onload.

protected void Page_Load(object sender, EventArgs e)
        {
            doif = Convert.ToInt32(Request.QueryString["DOIF"]);
            if (doif == 1)
            {

                rec = Request.QueryString["ORDCODE"].ToString();
                rec_id = Convert.ToInt32(rec);
                dl.DeleteCompany(rec_id);
                Response.Redirect("CompanySetup.aspx");
                //Page.RegisterStartupScript("close", "<script>self.close();</script>");
                //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
            }
}


plz let me know, if u get it.

its working good in all my projects.
 
Share this answer
 
Comments
Member 10263519 22-Jan-14 4:18am    
i don't have another page (del.aspx).i can enter either memberid or card id ,to delete.
abdul subhan mohammed 22-Jan-14 4:20am    
if u dont del.aspx page, add it, u just need to add backend code for delete... after delete, redirect the page again to the content or list of members page, that's it...
Member 10263519 22-Jan-14 5:22am    
<script language="javascript" type="text/javascript">
function ConfirmOnDelete(memberid,cardid) {
if (confirm("Are you SURE you want to Delete") == true) {
window.location = "del.aspx?memberid="<%=txtememid.Text%> "&cardid="<%=txtcardid.Text%>;
return true;
}


and button
<button id="btndok" value="Delete" önclick="ConfirmOnDelete('<%# Eval("memberid,cardid") %>')">
</button>

and in page load
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

please help me, can i write is there any wrong

abdul subhan mohammed 22-Jan-14 4:22am    
from every page, i'm calling this del.aspx to delete, i think i have morethan 10 pages in my project, n i'm calling it 10 times, using quering string
If am in your shoes i will just do simple javascript / jquery validation to check whether the trimmed value inside the textbox is having proper length>0 or not then i will Run your script.

<script type="text/javascript">
     function DeleteItem() {
          if ($("#TextBox1").val().trim()!="") { 
              if (confirm("Are you sure you want to delete ...?")) {
                return true;
              }
               return false;

             } 
            else { 
               alert('Please enter the text') 
               return false; 
             } 
     }
 </script>
</script>
 
Share this answer
 
v2
Comments
Member 10263519 22-Jan-14 6:02am    
ok, but my textbox is in ajaxtabcontrol tab.

<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"
>   </td> <td></td></tr>



<tr><td></td><td align="right">Card ID: </td><td class="style1">
<asp:TextBox ID="txtdcardid" runat="server"
>   </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>









how to get the value of that textbox(txtdmemid)
Pavan_N 22-Jan-14 6:07am    
Thats fine. JQuery/Javascript is a client side running script. Until and unless your control is available the script will work..... Fact is what ever the controls you use in your asp.net, php, jsp etc Finally browser understands HTML only. See the viewsource in your browser than you will realize.

Regards,
Pavan N
Member 10263519 22-Jan-14 6:21am    
ok, how can i get txtdmemid textbox value into javascript.
Help me am strugling a lot with this issue.
Pavan_N 22-Jan-14 6:29am    
Same as mentioned in my snippet above.
TRY alert($("#txtdmemid").val());
Member 10263519 22-Jan-14 6:33am    
if i write this, when i hit OK button it's not displaying popup.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using DataAccessLayer;


namespace ITACS
{
    public partial class del : System.Web.UI.Page
    {
        SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
        string rec = ""; int rec_id = 0, doif = 0; DAL dl = new DAL();
        protected void Page_Load(object sender, EventArgs e)
        {
            doif = Convert.ToInt32(Request.QueryString["DOIF"]);
            if (doif == 1)
            {

                rec = Request.QueryString["ORDCODE"].ToString();
                rec_id = Convert.ToInt32(rec);
                dl.DeleteCompany(rec_id);
                Response.Redirect("CompanySetup.aspx");
                //Page.RegisterStartupScript("close", "<script>self.close();</script>");
                //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
            }
            else if (doif == 2)
            {
                int bid = Convert.ToInt32(Request.QueryString["BID"]);
                dl.DeleteBranch(bid);
                Response.Redirect("BranchSetup.aspx");
            }
            else if (doif == 3)
            {
                int deptid = Convert.ToInt32(Request.QueryString["DEPTID"]);
                dl.DeleteDepartment(deptid);
                Response.Redirect("DeptSetup.aspx");
            }
            else if (doif == 4)
            {
                int supid = Convert.ToInt32(Request.QueryString["SUPCODE"]);
                dl.DeleteSupplier(supid);
                Response.Redirect("SupplierSetup.aspx");
            }
            else if (doif == 5)
            {
                int uid = Convert.ToInt32(Request.QueryString["USERCODE"]);
                dl.DeleteUser(uid);
                Response.Redirect("userSetup.aspx");
            }
            else if (doif == 6)
            {
                int itemid = Convert.ToInt32(Request.QueryString["ITEMCODE"]);
                dl.DeleteItem(itemid);
                Response.Redirect("DeviceSetup.aspx");
            }
            else if (doif == 7)
            {
                string SIMCODE = Convert.ToString(Request.QueryString["SIMCODE"]);
                dl.DeleteSIM(SIMCODE);
                Response.Redirect("SIMSetup.aspx");
            }
            else if (doif == 8)
            {
                int CONNECTID = Convert.ToInt32(Request.QueryString["CONNECTID"]);
                dl.DeleteConnect(CONNECTID);
                Response.Redirect("AssignConnect.aspx");
            }
        }
    }
}
 
Share this answer
 
Comments
Member 10263519 22-Jan-14 4:42am    
ConfirmOnDelete('<%# Eval("MobileNo")

there u have taken only mobile no,but i need to pass either memberid or cardid .
if i any one that record should be deleted.
abdul subhan mohammed 22-Jan-14 4:45am    
just add comma n add values as many as u like...provide values in d button onclick, then in javascript delete(val1, val2,...)
n then in del.aspx as well...
Member 10263519 22-Jan-14 4:48am    
<script language="javascript" type="text/javascript">
function ConfirmOnDelete(memberid/cardid) {
if (confirm("Are you SURE you want to Delete") == true) {
window.location = "del.aspx?memberid=" + txtdmemid.text + "&cardid=" +txtdcardid.text;
return true;
}
</script>

shall i write like this.


onclick="ConfirmOnDelete('<%# Eval("MobileNo") %>')"

here is Eval predefined fun or not.

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