[研究][ASP.NET]JavaScript alert對話盒視窗彈出位置測試
2022-04-21
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#
因為之前這篇,使用不同的彈出方式,影響了版面美工,所以測試一下
[研究][ASP.NET]登入畫面表單美工設計(三)
http://shaurong.blogspot.com/2022/04/aspnet_14.html
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:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" /><br />
<asp:Button ID="Button3" runat="server" Text="Button" OnClick="Button3_Click" /><br />
<asp:Button ID="Button4" runat="server" Text="Button" OnClick="Button4_Click" /><br />
</div>
</form>
</body>
</html>
|
Default.aspx.cs
using System;
using System.Web.UI;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// 網頁不會空白
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message",
"<script language='javascript' defer>alert('測試1。');</script>");
}
protected void Button2_Click(object sender, EventArgs e)
{
// 網頁會空白
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),
"message", "<script language='javascript' defer>alert('測試2。');</script>");
}
protected void Button3_Click(object sender, EventArgs e)
{
//轉向
Page.ClientScript.RegisterStartupScript(Page.GetType(),
"message", "<script language='javascript' defer>alert('測試3。');
window.location='Default2.aspx'</script>");
}
protected void Button4_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('測試4。');</script>");
}
}
} |
執行結果
HTML Source
|
| |
| | <!DOCTYPE html>
| |
| | <html xmlns="http://www.w3.org/1999/xhtml">
| | <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
| |
| | </title></head>
| | <body>
| | <form method="post" action="./Default.aspx" id="form1">
| | <div class="aspNetHidden">
| | <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="o9slSZhygiMVNvGkKm7W+AC6+Upc xpuluNY9PxJ6uGlVm+ehQeKP8QRpNI+K6U9nur+OOzh5XxhxiBfLLisaobAvcFJWfEtFFX6uGA2SoVY=" />
| | </div>
| |
| | <div class="aspNetHidden">
| |
| | <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
| | <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="2YiTg3ryJ9ZjOyW5pJk8lCLyCR9oq8jPQ5Rqx/wsr4TFuFAufY8ae6bZsfYnTc+DVh9/GBUBE/Pif9gK6SZGJ KL56dq1O49gFugO2t0nbRFqhFeS+yHfppLGsEiHOAaEcwdpDhhrSYZd7Ja6MbXcakAxKZz5brdMjeb64B/YwrbDdjh3 fYVjoearqWw6oEdb" />
| | </div>
| | <div>
| | <input type="submit" name="Button1" value="Button" id="Button1" /><br />
| | <input type="submit" name="Button2" value="Button" id="Button2" /><br />
| | <input type="submit" name="Button3" value="Button" id="Button3" /><br />
| | <input type="submit" name="Button4" value="Button" id="Button4" /><br />
| | </div>
| | </form>
| | </body>
| | </html>
| | |
|
********************************************************************************
按鈕1執行結果
按下「確定」按鈕後,檢視HTML Source
|
| |
| | <!DOCTYPE html>
| |
| | <html xmlns="http://www.w3.org/1999/xhtml">
| | <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
| |
| | </title></head>
| | <body>
| | <form method="post" action="./Default.aspx" id="form1">
| | <div class="aspNetHidden">
| | <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="V/URd1sI61D1R20GkaO2JMbyRBpYC a3oyrpLmbHXV0l5TRB8YRPcCeoMW9bAdv7x+FqZENO7yC5HD26km+ESvjmaHyMj06upTT1WpHmtNjA=" />
| | </div>
| |
| | <div class="aspNetHidden">
| |
| | <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
| | <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="58gvSY0JmeL5tCExZ8oAcWDBnQYcIqhTp1CUDx/NUAlVjoVQ8Xe2MMd4QD4vW76eq/cAiqVHc5gRKM26D++uX LsHKWi4Gs+JVX9las/jt0ULZ7K0i06eWGDdTWxkJBbmglMeSD0kAI8Blqh2Txu2DSDOw8QJuBukWhlKcRxxVc4f4Uqk nNiMp/la8HtNw6UG" />
| | </div>
| | <div>
| | <input type="submit" name="Button1" value="Button" id="Button1" /><br />
| | <input type="submit" name="Button2" value="Button" id="Button2" /><br />
| | <input type="submit" name="Button3" value="Button" id="Button3" /><br />
| | <input type="submit" name="Button4" value="Button" id="Button4" /><br />
| | </div>
| |
| | <script language='javascript' defer>alert('測試1。');</script></form>
| | </body>
| | </html>
| | |
|
********************************************************************************
按鈕2執行結果
按下「確定」按鈕後,檢視HTML Source
| | | | | |
| |
| | <!DOCTYPE html>
| |
| | <html xmlns="http://www.w3.org/1999/xhtml">
| | <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
| |
| | </title></head>
| | <body>
| | <form method="post" action="./Default.aspx" id="form1">
| | <div class="aspNetHidden">
| | <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="4ME0Bu06b3I2m1E97XWIY58QhwN Bd5+baNZV0a/t3DUD38liJGN9uBYsU4NjdjbZ+/6Nv4HPzjhmZj6sZnJuN0Ln+bNLi7pm3aIbO7RI8eY=" />
| | </div>
| |
| | <script language='javascript' defer>alert('測試2。');</script>
| | <div class="aspNetHidden">
| |
| | <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
| | <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="hEZjvkte3Odzv9KOrHUh4TkVpfaXe9jONEzp57b6rAyoiFUzPlA8/GEpdwyV3zw62MwWmoT9FKlWuqc0tY DSH0p4u4pjtb09piW8dgEGbOtYieCJt0WSjcSJzOM+DOm/kxiOohR1BcNeUI4TyNhp9lYC8Lz68GvKe44ioBp2SFr K/r/+PqEpfVLSSLR+yAwj" />
| | </div>
| | <div>
| | <input type="submit" name="Button1" value="Button" id="Button1" /><br />
| | <input type="submit" name="Button2" value="Button" id="Button2" /><br />
| | <input type="submit" name="Button3" value="Button" id="Button3" /><br />
| | <input type="submit" name="Button4" value="Button" id="Button4" /><br />
| | </div>
| | </form>
| | </body>
| | </html>
| | |
| | |
|
********************************************************************************
按鈕3執行結果,因為轉址到 Default2.aspx 了,不檢視
********************************************************************************
按鈕4執行結果
按下「確定」按鈕後,檢視HTML Source
| | | | | | <script>alert('測試4。');</script>
| |
| | <!DOCTYPE html>
| |
| | <html xmlns="http://www.w3.org/1999/xhtml">
| | <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
| |
| | </title></head>
| | <body>
| | <form method="post" action="./Default.aspx" id="form1">
| | <div class="aspNetHidden">
| | <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="h7NFRRI447D991l2ZQcy+9JFtiY rPds9xYts5NmrhmiDnphRBshNVXvDXoJLtKkY1a/iJvDZIJDGqlrCtdweebYgaG13QzqqMJTRO5Rlflg=" />
| | </div>
| |
| | <div class="aspNetHidden">
| |
| | <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
| | <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="7cdoDgcjEodG4L/ihUVTKy1F95vzm00YhJe7kC73m2hpB6V6WqiHO4b6/jeGFTAkl0C6iJonsXGFUTIHMom Hi7dKcVZaEeQZCkxpjRSH2THwknHv3hYS9hmarSSWgmCIX+PeAkbYUSc1WbSETL7r5KNlxuISDz349vOtxc1zbv/Dt 9yDBw/o41z8bF8A41m3" />
| | </div>
| | <div>
| | <input type="submit" name="Button1" value="Button" id="Button1" /><br />
| | <input type="submit" name="Button2" value="Button" id="Button2" /><br />
| | <input type="submit" name="Button3" value="Button" id="Button3" /><br />
| | <input type="submit" name="Button4" value="Button" id="Button4" /><br />
| | </div>
| | </form>
| | </body>
| | </html>
| | |
| | |
|
********************************************************************************
結論:
使用 Response.Write("<script>alert('測試4。');</script>"); 結果在 HTML Source 會出現在 <html> 之前,有點怪異,所以可能盡量避免這種。
(完)
相關
沒有留言:
張貼留言