67-100 為button單擊事件新增客戶端指令碼
阿新 • • 發佈:2021-12-14
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DeWeb06.aspx.cs" Inherits="asp.netTest.Demo01.DeWeb06" %> <!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 runat="server"> <title></title> <script type="text/javascript"></script> </head> <body> <form id="form1" runat="server"> <div> 學號: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <%-- 加入事件的按鈕--%><asp:Button ID="btnDel" OnClientClick="return confirm('確認刪除嗎?')" runat="server" Text="刪除" onclick="btnDel_Click" /> <asp:Literal ID="Itamsg" runat="server"></asp:Literal> </div> </form> </body> </html>
C#後端類
using System;using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace asp.netTest.Demo01 { public partial class DeWeb06 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } // 事件方法中去訪問 ,控制元件ID protected void btnDel_Click(object sender, EventArgs e) { this.Itamsg.Text = "刪除成功!"; } } }
效果