[ASP.NET] 在後台顯示ALERT警告視窗

  • 27655
  • 0

摘要:[ASP.NET] 在後台顯示ALERT警告視窗

今天同事問我一個問題

如何在後台顯示Javascript的Alert()

小弟順便紀錄一下

 

前台test.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="按下跳出Alert_1" OnClick="Button1_Click" />
        <br />
        <br />
        <br />
        <asp:Button ID="Button2" runat="server" Text="按下跳出Alert_2" OnClick="Button2_Click" />
    </div>
    </form>
</body>
</html>

 

後台test.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<Script language='JavaScript'>alert('Y2J測試!');</Script>");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        //\\r或是\\n都可以正常使用
        Response.Write("<Script language='JavaScript'>alert('第一行\\r第二行\\r\\r第四行');</Script>");
        Response.Write("<Script language='JavaScript'>alert('第一行\\n第二行\\n\\n第四行');</Script>");
    }
}

 

 

 

 

 

 

 






Y2J's Life:http://kimenyeh.blogspot.tw/