如何在不使用 runat 服务器的情况下单击 html 提交控件时执行某些操作

How to perform some action when i click on html submit control without using runat server

我的 asp.net 网络表单中有 2 个文本框和 1 个提交按钮。这些控件纯粹是 HTML 控件,我不想使用 runat="server" 属性.

现在,当用户单击提交按钮时,应该执行一些操作。对于我必须编写代码的地方,以及如何在*.aspx.cs页中编写代码。

还有一个问题是,如何维护我的 html 控件的状态。请澄清我的疑问

我不确定是否理解你的问题,但如果你想保持 HTML 形式是纯粹的 HTML,你可以使用通用 Web 处理程序,在你的 [=24= 中添加一个处理程序]:

<system.webServer>
<handlers>
  <remove name="Handler Name" />
  <add name="Handler Name" verb="POST" type="Handler Name" path="/Handlerpath.ashx" />
</handlers>

HTML:

<form name="myform" method="POST" action="/Handlerpath.ashx"><input type="text" name="foo" /> </form>

创建一个 class 并使用 IHttphandler 界面作为基础 class:

class myhandler : IHttphandler{}

然后使用ProcessRequest方法获取表单数据。

        var foo = context.Request.Form["foo"];