简体   繁体   English

是否有可能从表单标签中获取html按钮单击事件?

[英]is it possible to get html button clicked event out of the form tag?

i was wondering if we can get the events of a asp or html element out of the form tag ? 我想知道我们是否可以从form标记中获取asp或html元素的事件?
default.aspx : default.aspx:

<head runat="server">
<link href="CSS/main.css" rel="stylesheet" type="text/css" />
<title>test title</title>
</head>
<body>
    <script>
        this.
    </script>
    <div class="container">
        <a id="aOnHtml" runat="server">Test</a>
        <button id="btnID" runat="server" onclick="btnClicked" > BTN </button>
    </div>

</body>
</html>

and default.aspx.cs : 和default.aspx.cs:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnID.ServerClick += new EventHandler(this.btnClicked);

    }
    void btnClicked(Object sender , EventArgs e)
    {
        aOnHtml.InnerText = "Clicked";
    }
}

i have break point at the begging of btnClicked function which it doesn't get there at all ,what is the problem ? 我在btnClicked函数的乞讨时遇到了断点,根本无法解决问题,这是什么问题?

You are missing the basic form element which you need to make this work. 您缺少进行此工作所需的基本表单元素。 Take a look at this : http://www.w3schools.com/aspnet/aspnet_forms.asp 看看这个: http : //www.w3schools.com/aspnet/aspnet_forms.asp

您要做的是:1.使用<asp:button>代替<button> 2.获得btnID.ClickbtnID.ClientClick而不是btnID.ServerClick ,一切都会好起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM