首页 > 解决方案 > asp.net aspx OnClick 在客户端服务过程中单击时不会触发

问题描述

我有 Default.cs 文件和 Default.aspx.cs 文件。我使用 OnClick 和 OnServerClick 方法实现 rules_abort_execution_button 的地方。这两个功能都在 Default.cs UI 按钮中实现:Default.aspx.cs

<div id="rules_execution_dialog" runat="server" class="theme-border">
    <div id="rules_execution_dialog_drag_control" title="Drag me">
        <img id="rules_execution_dialog_maximize_button" src="./Resources/Theme/Images/maximize.png" alt="Maximize" title="Maximize" />
        <br style="clear: both" />
    </div>
    <div style="margin-top: 10px">
        <input class="btn" id="rules_execute_close_button" type="button" value="Close" disabled="disabled" onclick=" dialogClosed($('rules_execution_dialog')) " style="float: right; min-width: 0px; width: 70px;" />
        <input class="btn" id="rules_abort_execution_button" type="button" value="Abort execution" runat="server" OnClick="abort_click" OnServerClick="btn_Abort_Click" style="float: right; min-width: 0px; width: 90px;" />
        <br style="clear: both" />
    </div>
</div>

Default.cs的两个功能:

protected void btn_Abort_Click(object sender, EventArgs e)
{
    var IamHere = "";
    return;
}

protected void abort_click(object sender, EventArgs e)
{
    var test = "";
    return;
}

当我从另一个文件执行 Soap 客户端方法Download.cs以获取数据时,它需要很长时间,所以我想添加可以允许中止执行的中止按钮。但不幸的是,在从第三方客户端获取数据时,我的 UI 没有响应我的 UI 单击按钮方法。我尝试了各种示例,但没有找到解决方案。

标签: c#asp.netbuttonclientaspx-user-control

解决方案


OnClick="abort_click" OnServerClick="btn_Abort_Click"

Onclick 应该是 javascript

示例代码

 <%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="WebApplication2.About" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%: Title %>.</h2>
    <h3>Your application description page.</h3>
    <p>Use this area to provide additional information.</p>
    <input id="Button1" type="button" value="button"  runat="server" onclick="alert('hi');" onserverclick="Button1_ServerClick"/>
</asp:Content>

服务器端

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class About : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

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

推荐阅读