asp.net中<input type=button>无法调用后台函数
例如:用<inputid="bt1"type="button"runat="server"Onclick="delete"/>添加一个按钮(注:不是从工具箱拖进去的控件)...
例如:用<input id="bt1" type="button" runat="server" Onclick="delete"/>添加一个按钮(注:不是从工具箱拖进去的控件)
在default.aspx.cs中有个delete()方法
但是按钮bt1无法实现delete功能,请问为何? 该如何改进? 展开
在default.aspx.cs中有个delete()方法
但是按钮bt1无法实现delete功能,请问为何? 该如何改进? 展开
2个回答
展开全部
Onclick 改成OnSeverClick
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HtmlControl.aspx.cs" Inherits="WebApp.HtmlControl" %>
<!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>
<input type="button" onserverclick="delete" value="test" runat="server" />
</div>
</form>
</body>
</html>
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");
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HtmlControl.aspx.cs" Inherits="WebApp.HtmlControl" %>
<!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>
<input type="button" onserverclick="delete" value="test" runat="server" />
</div>
</form>
</body>
</html>
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");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询