事件OnClick无法在单声道ASP.NET c#中工作。
点击后,页面会刷新
Test.aspx文件
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Simple.Views.Home.Test" %>
<asp:Content id="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<p>
<asp:Button id="NextButton" Text="Next" runat="server" OnClick="NextButton_OnClick" />
</p>
</asp:Content>
Test.aspx.cs
using System;
using System.Web;
using System.Web.Mvc;
namespace Simple.Views.Home
{
public partial class Test : ViewPage
{
protected void Page_Load (object sender, EventArgs e)
{
//NextButton.Click += new EventHandler (NextButton_OnClick);
}
protected void NextButton_OnClick(object sender, EventArgs e)
{
if (!Page.ClientScript.IsStartupScriptRegistered ("AlertTest"))
ClientScript.RegisterStartupScript (typeof(ViewPage), "AlertTest", @"<script language='javascript'>alert('Hello world');</script>");
Response.Redirect ("~/Home/Next");
}
}
}
点击后,页面会刷新