gpt4 book ai didi

c# - 如何记录提交表单的链接点击?

转载 作者:行者123 更新时间:2023-11-29 20:08:55 25 4
gpt4 key购买 nike

我想跟踪用户事件(日志数据)。我在页面上有几个通过特定方式提交表单的链接。问题是:

我找不到合适的方法来处理点击事件并以简单的方式将日志插入数据库。

我的代码:

HtmlGenericControl a = new HtmlGenericControl("a");
a.Attributes["onclick"] = "$('#" + frm.ClientID + "').submit();";
a.InnerText = "site " + dt_list.ElementAtOrDefault(0).Field<string>("pro_name").TrimEnd();
inner_li_1.Controls.Add(a);

现在我想处理提交链接的点击事件?!!

最佳答案

这太多了,无论它如何工作,我在某些情况下使用它,我不能用其他方式做。

javascript调用,我是先调用log,然后继续提交。当我点击时,我还显示了一条等待消息,事件发生得太快了,用户不明白这是在等待什么。我还注意避免使用简单的 javascript 重复记录操作。我在 onclick 事件上调用此函数。

var confirmSubmited = false;
function SubmitWithLog(me)
{
// to avoid many clicks...
if(confirmSubmited)
return false;

confirmSubmited=true;

jQuery.ajax({
url: "/LogAction.ashx",
type: "GET",
timeout: 3000,
async: true, // you can try and async:false - maybe is better for you
data: action=4, // here you send the log informations
cache: false,
success: function(html) {
jQuery("#FormID").submit();
},
error: function(responseText, textStatus, XMLHttpRequest) {
jQuery("#FormID").submit();
}
});

return false;
}

处理程序是

public class LogAction : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// log here what you wish

// end up with no content
context.Response.TrySkipIisCustomErrors = true;
context.Response.Status = "204 No Content";
context.Response.StatusCode = 204;
}
}

我想明确,这不是记录用户操作的好方法,但它是您别无选择时的一种方法。我只使用它,当用户提交并离开我的站点并转到另一个站点时,我用它来编写此操作。

在所有其他情况下,我在 url 中使用 ether 引用,ether 使登录代码隐藏,ether 我在 html 页面中包含一个空图像,使日志如下所示:ASP server stats for html pages

我已经尝试调用 ajax,并以正确的方式进行提交,但它失败了,ajax 被提交停止了。下一种方法是使用超时,调用 ajax,并将超时设置为 500ms 以进行提交,但我避免了超时,因为 ajax 调用花费的时间不到 100ms,因为我已经做到了。

关于c# - 如何记录提交表单的链接点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10968725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com