最好的办法是使用 jquery 之类的框架,然后绑定到按钮,调用服务并处理响应。下面是一个简单的例子。
$(document).ready(function()
    $('#Button1').bind('click', function () { 
        // This grabs the page you are in so that you can call it correctly
        var pagePath = window.location.pathname;  
        var testId = $("#some_div").val();
        var url = pagePath + "/TestService";          
        $.post(url, { id: testId },
            function (data) {
                showAlert(data);
            }
        });
    };
});
首先,您需要确保文档在某个时候准备就绪。Bind 允许在文档加载时绑定按钮。然后,通过单击它,您执行获取 testId、调用您的服务并在成功回调中处理数据响应的匿名函数。
希望这能让你朝着正确的方向开始!
编辑:添加后端网络表单“服务”曝光
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e) 
    {
    }
    [WebMethod]
    public static string TestService(string id) 
    {
        var string = DBCollection.FirstOrDefault(x => x.id == id); // Or whatever you want to return the data
        return "You called me on " + DateTime.Now.ToString() + "with " + string;
    }
}
这将允许您调用页面上公开的“WebMethod”。有关此方面的更多帮助,请参阅以下链接。
http://www.tugberkugurlu.com/archive/asp-net-web-forms---calling-web-service-page-methods-using-jquery
编辑:在网络表单中执行此类方法时的其他注意事项。
在 asp.net webforms 中使用 jquery 调用 webmethod