2021年12月15日 星期三

[研究][ASP.NET] F5按鍵是否會重複上次更新值動作的測試

[研究][ASP.NET] F5按鍵是否會重複上次更新值動作的測試

2021-12-15

Visual Studio 2022 + ASP.NET + C# + WebForm + Web Application

一般瀏覽器畫面上按下鍵盤的 F5按鍵,是更新畫面的意思。

如果剛剛做的動作是更新某值,按下F5會否拿畫面值重做一次更新動作?

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">
        <div>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" 
DeleteCommand="DELETE FROM [Table1] WHERE [id] = @id" 
InsertCommand="INSERT INTO [Table1] ([FieldText], [FieldDateTime], [FieldInt], [FieldBit]) VALUES (@FieldText, @FieldDateTime, @FieldInt, @FieldBit)" 
SelectCommand="SELECT * FROM [Table1]" 
UpdateCommand="UPDATE [Table1] SET [FieldText] = @FieldText, [FieldDateTime] = @FieldDateTime, [FieldInt] = @FieldInt, [FieldBit] = @FieldBit WHERE [id] = @id">
                <DeleteParameters>
                    <asp:Parameter Name="id" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="FieldText" Type="String" />
                    <asp:Parameter Name="FieldDateTime" Type="DateTime" />
                    <asp:Parameter Name="FieldInt" Type="Int32" />
                    <asp:Parameter Name="FieldBit" Type="Boolean" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="FieldText" Type="String" />
                    <asp:Parameter Name="FieldDateTime" Type="DateTime" />
                    <asp:Parameter Name="FieldInt" Type="Int32" />
                    <asp:Parameter Name="FieldBit" Type="Boolean" />
                    <asp:Parameter Name="id" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
            <asp:DetailsView ID="DetailsView1"  DefaultMode="Edit"
                runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="id" DataSourceID="SqlDataSource1">
                <Fields>
                    <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
                    <asp:BoundField DataField="FieldText" HeaderText="FieldText" SortExpression="FieldText" />
                    <asp:BoundField DataField="FieldDateTime" HeaderText="FieldDateTime" SortExpression="FieldDateTime" />
                    <asp:BoundField DataField="FieldInt" HeaderText="FieldInt" SortExpression="FieldInt" />
                    <asp:CheckBoxField DataField="FieldBit" HeaderText="FieldBit" SortExpression="FieldBit" />
                    <asp:CommandField ShowEditButton="True" />
                </Fields>
            </asp:DetailsView>
        </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
namespace WebApplication1
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}






實際測試,會。而且畫面實際上有彈出對話盒視窗做警告

確認重新提交表單

您尋找的網頁是用了您輸入的資料。返回該頁會重複您剛才的動作。您確定
要繼續嗎?

(完)


沒有留言:

張貼留言