salim ali

salim ali

  • NA
  • 20
  • 965

Show "registration successfully" after saving or modifying the timer

Feb 8 2021 12:55 PM
Can you help me fix the code ..
 
In addition, I want to display with the timer the phrase "registration successfully" after saving or modifying
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dashbord.aspx.cs" Inherits="Login.Dashbord" %>  
  2. <!DOCTYPE html>  
  3. <html xmlns="http://www.w3.org/1999/xhtml">    
  4. <head runat="server">    
  5.     <title></title>    
  6.     <style type="text/css">    
  7.         .auto-style1 {    
  8.             width: 100%;    
  9.         }    
  10.         .auto-style2 {    
  11.         }    
  12.         .auto-style3 {    
  13.             margin-left: 120px;    
  14.         }    
  15.         .auto-style4 {    
  16.             width: 22px;    
  17.             height: 27px;    
  18.             margin-left: 120px;    
  19.         }    
  20.         .auto-style5 {    
  21.             height: 27px;    
  22.         }    
  23.         .auto-style6 {    
  24.             margin-left: 120px;    
  25.         }    
  26.     </style>    
  27. </head>    
  28. <body>    
  29.     <form id="form1" runat="server">    
  30.     <div>    
  31.         
  32.         <table class="auto-style1">                
  33.             <tr>    
  34.                 <td class="auto-style2" colspan="2"><strong>Save/Update</strong></td>    
  35.             </tr>    
  36.             <tr>    
  37.                 <td class="auto-style6"></td>    
  38.                 <td>    
  39.                     <asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="#33CC33" Text="Register Successfully"></asp:Label>    
  40.                 </td>    
  41.             </tr>    
  42.             <tr>    
  43.                 <td class="auto-style4">Name</td>    
  44.                 <td class="auto-style5">    
  45.                     <asp:TextBox ID="TextBox2" runat="server" Width="175px" ></asp:TextBox>    
  46.                 </td>    
  47.             </tr>    
  48.             <tr>    
  49.                 <td class="auto-style6">Password</td>    
  50.                 <td>    
  51.                     <asp:TextBox ID="TextBox3" runat="server" Width="174px" ></asp:TextBox>    
  52.                 </td>    
  53.             </tr>    
  54.             <tr>    
  55.                 <td class="auto-style6"> </td>    
  56.                 <td>    
  57.                      </td>    
  58.             </tr>    
  59.             <tr>    
  60.                 <td class="auto-style3" colspan="2">    
  61.                     <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="663px">    
  62.                         <Columns>    
  63.                             <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />    
  64.                             <asp:BoundField DataField="EMPNAME" HeaderText="EMPNAME" SortExpression="EMPNAME" />    
  65.                             <asp:BoundField DataField="PASSWORD" HeaderText="PASSWORD" SortExpression="PASSWORD" />    
  66.                             <asp:CommandField ShowSelectButton="True" />    
  67.                         </Columns>    
  68.                     </asp:GridView>    
  69.                 </td>    
  70.             </tr>    
  71.             <tr>    
  72.                 <td class="auto-style3" colspan="2">    
  73.                     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TblLoginConnectionString %>" OnSelecting="SqlDataSource1_Selecting" SelectCommand="SELECT DISTINCT * FROM [tblUser]"></asp:SqlDataSource>    
  74.                 </td>    
  75.             </tr>  
  76.             <tr>    
  77.                 <td class="auto-style6" colspan="2">  
  78.         <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>  
  79.                 </td>    
  80.             </tr>  
  81.         </table>  
  82.     </div>    
  83.         <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Save" Width="115px" />   
  84.         <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Serach" Width="115px" />
  85.         <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Update" Width="106px" />  
  86.         <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Delete" Width="113px" />    
  87.                  </form>    
  88. </body>    
  89. </html>    
  1. using System;    
  2. using System.Collections.Generic;    
  3. using System.Linq;    
  4. using System.Web;    
  5. using System.Web.UI;    
  6. using System.Web.UI.WebControls;    
  7. using System.Data;    
  8. using System.Data.SqlClient;    
  9.     
  10. namespace Login    
  11. {    
  12.     public partial class Dashbord : System.Web.UI.Page    
  13.     {    
  14.         protected void Page_Load(object sender, EventArgs e)    
  15.         {    
  16.     
  17.         }    
  18.     
  19.         protected void Button1_Click(object sender, EventArgs e)    
  20.         {    
  21.             SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
  22.             SqlCommand cmd = new SqlCommand("insert into tblUser (EMPNAME,PASSWORD) values (@EMPNAME,@PASSWORD)", cn);    
  23.             cn.Open();    
  24.             cmd.Parameters.AddWithValue("EMPNAME", TextBox2.Text);    
  25.             cmd.Parameters.AddWithValue("PASSWORD", TextBox3.Text);    
  26.             cmd.ExecuteNonQuery();    
  27.             cn.Close();    
  28.         }    
  29.     
  30.         protected void Button2_Click(object sender, EventArgs e)    
  31.         {    
  32.             SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
  33.             cn.Open();    
  34.             DataTable dt = new DataTable();    
  35.             SqlDataAdapter sd = new SqlDataAdapter("select EMPNAME,PASSWORD from tblUser where EMPNAME= '" +TextBox2.Text+"'", cn);    
  36.             sd.Fill(dt);    
  37.             if (dt.Rows.Count > 0)    
  38.             {    
  39.                 TextBox2.Text=Convert.ToString(dt.Rows[0]["EMPNAME"]);    
  40.                 TextBox3.Text=Convert.ToString(dt.Rows[0]["PASSWORD"]);    
  41.             }    
  42.               
  43.                
  44.     
  45.             //using (SqlDataReader da=cmd.ExecuteReader())    
  46.             //{    
  47.             //    if (da.Read())    
  48.             //    {    
  49.     
  50.             //        TextBox2.Text = da.["EMPNAME"].ToString();    
  51.             //        TextBox3.Text = da["PASSWORD"].ToString();    
  52.                        
  53.             //    }    
  54.             //    else    
  55.     
  56.             //    {    
  57.             //        Label1.Text = "Not found";    
  58.             //    }    
  59.             //}    
  60.     
  61.         }    
  62.     
  63.         protected void Button3_Click(object sender, EventArgs e)    
  64.         {    
  65.             SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
  66.             SqlCommand cmd = new SqlCommand("Update tblUser set PASSWORD=@PASSWORD where EMPNAME=@EMPNAME", cn);    
  67.             cn.Open();    
  68.             cmd.Parameters.AddWithValue("EMPNAME", TextBox2.Text);    
  69.             cmd.Parameters.AddWithValue("PASSWORD", TextBox3.Text);    
  70.             cmd.ExecuteNonQuery();    
  71.             cn.Close();    
  72.     
  73.         }    
  74.     
  75.         protected void Button4_Click(object sender, EventArgs e)    
  76.         {    
  77.             SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
  78.             SqlCommand cmd = new SqlCommand("Delete from tblUser where EMPNAME=@EMPNAME", cn);    
  79.                
  80.             cn.Open();    
  81.             TextBox2.Text = "";    
  82.             TextBox3.Text = "";    
  83.             cmd.ExecuteNonQuery();    
  84.     
  85.         }    
  86.     
  87.         ////protected void Timer1_Tick(object sender, EventArgs e)    
  88.         //{    
  89.               
  90.         //}    
  91.     
  92.     
  93.         protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)    
  94.         {    
  95.     
  96.             SqlConnection cn = new SqlConnection("Data Source=DESKTOP-KH76KMV;Initial Catalog=TblLogin;Integrated Security=True");    
  97.             cn.Open();    
  98.             DataTable dt = new DataTable();    
  99.             SqlDataAdapter sd = new SqlDataAdapter("select EMPNAME,PASSWORD from tblUser where EMPNAME= '" + TextBox2.Text + "'", cn);    
  100.             sd.Fill(dt);    
  101.             if (dt.Rows.Count > 0)    
  102.             {    
  103.     
  104.                 GridView1.DataSource = tblUser;    
  105.                 GridView1.DataBind();    
  106.             }    
  107.     
  108.         }    
  109.          
  110.     }    
  111. } 

Answers (10)