[問題] ASP button 刪除警示功能修改

看板Web_Design作者 (小呆熊)時間7年前 (2017/05/24 15:00), 編輯推噓1(105)
留言6則, 4人參與, 最新討論串1/1
以下是我ASP的程式碼 想請教 如何修正 能在刪除前跳出確認刪除的視窗 (預防誤刪) .aspx <asp:ImageButton ID="delete" runat="server" Height="40px" ImageAlign="Middle" ImageUrl="~/images/Delfile.png" ToolTip="刪除" Width="40px" OnClick="delete_Click" /> .aspx.cs protected void delete_Click(object sender, ImageClickEventArgs e) { Literal myMsg = new Literal(); Literal myMsg1 = new Literal(); Literal myMsg2 = new Literal(); if (TextBox3.Text != "") { myMsg1.Text = "<script>alert('規畫書確定刪除?')</script><br>"; this.Page.Controls.Add(myMsg1); string strConn = ConfigurationManager.ConnectionStrings["lseformsConnectionString"].ConnectionString; System.Data.SqlClient.SqlConnection myConn = new System.Data.SqlClient.SqlConnection(strConn); myConn.Open(); string cmdTestText = "DELETE FROM [cancer_plan] WHERE [plan_no] = @plan_no"; System.Data.SqlClient.SqlCommand myCommand = new System.Data.SqlClient.SqlCommand(cmdTestText, myConn); myCommand.Parameters.AddWithValue(@"plan_no", TextBox36.Text); myCommand.ExecuteNonQuery(); myConn.Close(); myMsg2.Text = "<script>alert('規畫書已刪除!')</script><br>"; this.Page.Controls.Add(myMsg2); } else { myMsg.Text = "<script>alert('請輸入病歷號')</script><br>"; this.Page.Controls.Add(myMsg); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.22.165.64 ※ 文章網址: https://www.ptt.cc/bbs/Web_Design/M.1495609237.A.412.html

05/24 19:52, , 1F
換個思路,不要直接點了畫面上顯示的按鈕就呼叫del
05/24 19:52, 1F

05/24 22:27, , 2F
關鍵字 onclientclick confirm
05/24 22:27, 2F

05/26 04:22, , 3F
感謝 我懂了
05/26 04:22, 3F

05/31 00:42, , 4F
ASP != ASP.NET
05/31 00:42, 4F

05/31 00:43, , 5F
另外新手的話學MVC吧
05/31 00:43, 5F

05/31 00:43, , 6F
WebForm不好學習前後端串接
05/31 00:43, 6F
文章代碼(AID): #1P9I-LGI (Web_Design)