[研究]ASP.NET,WebForm,Default2.aspx 按下 Button1_Click 按鈕後,如何讓 Default.aspx 的 GridView1 做更新
2024-04-18
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19
********************************************************************************
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <a href="####" onclick="window.open('Default2.aspx?SN=2', '', 'scrollbars=yes,resizable=yes,width=600,height=400,left=10,top=10');" class="btn btn-outline btn-primary btn-xs">編輯</a> <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server"></asp:GridView> </form> </body> </html> |
Default.aspx.cs
不用改 |
********************************************************************************
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="WebApplication1.Default2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="儲存" OnClick="Button1_Click" /> </form> </body> </html> |
Default2.aspx.cs
using System;
namespace WebApplication1
{
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// 在按下按鈕後,用 JavaScript 重新載入 Default.aspx 頁面
Response.Write("<script>alert('儲存成功!!');window.opener.location.reload();window.close();</script>");
}
}
}
|
(完)
相關
沒有留言:
張貼留言