简体   繁体   English

将ASP.NET按钮转换为HTML按钮

[英]Convert ASP.NET Button to HTML button

I would like my button in asp convert to html button. 我希望将ASP中的按钮转换为html按钮。

<asp:ImageButton ID="UpdateButton" runat="server" CausesValidation="True" ValidationGroup="EditCustomer" CommandName="UpdateRow" ToolTip="Accept Changes" ImageUrl="~/Web/Images/accept-40x40.png" /> 

Code behind: 后面的代码:

protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
case "UpdateRow":

            UpdateCustomer();
            FormView1.ChangeMode(FormViewMode.ReadOnly);
            DisplayCustomer((int)FormView1.DataKey.Value);
            break;
        }
    }

My html button is not working now.. 我的html按钮现在无法使用。

<button type="button" class="btn btn-sm btn-success" title="Edit" ID="UpdateButton" runat="server" onserverclick="UpdateRow">

The problem is the event's implementation, when you use the attribute "OnServerClick" you must specify the event, no the CommandName, so you need to add an event like this to your code: 问题是事件的实现,当您使用属性“ OnServerClick”时,您必须指定事件,而不是CommandName,因此您需要在代码中添加如下事件:

protected void UpdateRow(object Source, EventArgs e) {
    UpdateCustomer();
    FormView1.ChangeMode(FormViewMode.ReadOnly);
    ...
}

If you want to use the button using the property CommandName, you can't use an HtmlButton. 如果要通过属性CommandName使用按钮,则不能使用HtmlButton。

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

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