Showing posts with label OnClientClick. Show all posts
Showing posts with label OnClientClick. Show all posts

How to add a confirm delete option in ASP.Net Gridview

Add a Confirm delete option in ASP.Net


Display multiple details in Gridview we want to delete some row before confirmation messahe open confirm delete that is onclientclick event Using Asp.Net C#.

DEMO


HTML CODING 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
    <table
        <tr><td>&nbsp;</td><td>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting">
                <Columns>
                    <asp:TemplateField HeaderText="Action" ShowHeader="False">
                        <ItemTemplate>

           <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
              
                OnClientClick="return confirm('Are You Sure Want to you Delete?');" Text="Delete">

           </asp:LinkButton>

                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="UserId" HeaderText="User Id" />
                    <asp:BoundField DataField="UserName" HeaderText="User Name" />
                    <asp:BoundField DataField="Location" HeaderText="Location" />
                    <asp:BoundField DataField="fromdate" HeaderText="FromDates" />
                </Columns>
                <HeaderStyle ForeColor="#CC3300" />
            </asp:GridView>
            </td></tr>
    </table>
    </div>
    </form>
</body>
</html>



 C# CODING


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data;

public partial class Mysql_StoredProcedure : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbc"].ToString());
        con.Open();
        MySqlCommand cmd = new MySqlCommand("select * from userinformation", con);

        MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        con.Close();

    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
     
        // Write Delete condition

        Response.Write("<script>alert('Deleted Successfully')</script>");

    }
}



 Add New Webform - Add Gridview - EditColumn -  Add Command field - Delete 





Next - Add - Delete Buttton - Convert into templatefield






Next - GridView - Edit Template - Add Delete - OnClientclick = return confirm('delete?');






Next - Html source shown below like






Next - Gridview Row events - Double click - RowDeleting



Add delete condition for required in rowdeleting event






Show Message or Popup Box Using Javascript,Jquery in Asp.Net C#

Message or Popup Box Show Using Javascript,Jquery

Show Message box or Popup Message  Display Clientside,Serverside Coding Using Javascript,Jquery in Asp.Net C#.

                             DEMO



                            Download

                          HTML Coding


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">

        function popup()
        {
            alert('This is Javascript Popup');
        }

        $(document).ready(function () {
            $("#JQuery_Popup").click(function () {
                alert("Jquery Popup");
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
    <table><tr><td>
        <asp:Button ID="Message" runat="server"  Text="Message" OnClick="Message_Click" />
        </td></tr>
        <tr><td>
        <asp:Button ID="Popup1Scripe_Popup1" runat="server" Text="Script Popup1" OnClick="Popup1Scripe_Popup1_Click" />
            </td></tr>
        <tr><td>
        <asp:Button ID="Popup2" runat="server" Text="Popup2" OnClick="Popup2_Click" />
            </td></tr>
        <tr><td><asp:Button ID="Javascript_Popup" runat="server" Text="Javascript Popup" OnClick="Javascript_Popup_Click" />
            </td></tr>
        <tr><td><asp:Button ID="OnClientClick" runat="server"  Text="OnClientClick Call Popup" OnClientClick="popup();" />
            </td></tr>

        <tr><td><asp:Button ID="JQuery_Popup" runat="server" Text="JQuery Popup" />
            </td></tr>
        </table>
    </div>
</form>
</body>
</html>



                                 C# Coding


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Message_Click(object sender, EventArgs e)
    {

        Response.Write("This is Message Write");

    }

    protected void Popup1Scripe_Popup1_Click(object sender, EventArgs e)
    {

        Response.Write("<script>alert('This is Script Popup')</script>");

    }
    protected void Popup2_Click(object sender, EventArgs e)
    {

        ClientScript.RegisterStartupScript(this.GetType(),"popup","alert('This is Popup2')",true);

    }
    protected void Javascript_Popup_Click(object sender, EventArgs e)
    {

        ClientScript.RegisterStartupScript(this.GetType(), "popu", "popup();", true);

    }
   

}

First - Create New WebForm - Add Buttons From toolBox - Onclientclick Event - Add Script Function  Name = popup()





JavaScript Popup Function Display Message & Jquery Button Click Show Popup Message




Next  - Add Code Behind - Button Event - Write popup Message








Confirm Message Box With OK or Cancel Option in C#

Confirm Message Box With OK or Cancel Option 


If Save Button Click Want To Confirmation Message Using OnClientClik Write Message Get MessageBox

         
                           DEMO




         
                     HTML CODING


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
    
    <asp:Button ID="Button1" runat="server" OnClientClick="return confirm('Do You Want To Save?');" Text="Save" />
    
</div>
</form>
</body>

</html>


First - Add - New Web Form  - Add Button - Go To - Property - OnClientClick Write Message





Next - Run [F5] - Click Button - Show Confirmation Message