asp.net中<input type=button>无法调用后台函数

2024-11-30 03:23:24
推荐回答(2个)
回答1:

Onclick 改成OnSeverClick

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HtmlControl.aspx.cs" Inherits="WebApp.HtmlControl" %>





无标题页










using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

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

}

protected void delete(object sender, EventArgs e)
{
Response.Write("test");
}
}
}

回答2:

html button 只能响应客户端事件,在浏览器里执行javascript 代码
asp.net button 事件代码则在服务器上运行,可以使用服务器资源
要么你把delete用javascript写在前台,要么你就把标签改为: