asp.net:监控用户点击

发布于 2025-01-06 14:20:51 字数 376 浏览 3 评论 0原文

我试图在用户单击超链接时触发事件。但它会抱怨该事件未定义:

<asp:HyperLink ID="HyperLink1" onmouseover="btnSubmit_Click" runat="server">www.google.com</asp:HyperLink>
<asp:Button
    id="btnSubmit"
    Text="Submit"
    Runat="server"  />
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        btnSubmit.Text = "clicked a link!!!";
    }

I'm trying to fire an event when a user clicks a hyperlink. But it would complain that the event is not defined:

<asp:HyperLink ID="HyperLink1" onmouseover="btnSubmit_Click" runat="server">www.google.com</asp:HyperLink>
<asp:Button
    id="btnSubmit"
    Text="Submit"
    Runat="server"  />
protected void btnSubmit_Click(object sender, EventArgs e)
    {
        btnSubmit.Text = "clicked a link!!!";
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

得不到的就毁灭 2025-01-13 14:20:51

我看到几个问题。

  1. 您的超链接上没有任何类型的点击事件设置。您确实有一个“onmouseover”,但基于MSDN文档 该控件没有单击事件。
  2. 您定义了一个按钮,但没有与该按钮关联的事件。
  3. 您有一个看似事件处理程序的函数,但命名约定表明它与没有事件的按钮关联。

您能提供更多关于您正在尝试做的事情的细节吗?我假设您发布的 C# 代码位于后面的代码中?

更新:

尝试将您的代码更改为此 -

<asp:LinkButton ID="lb_Link" OnClick="btnSubmit_Click" Text="www.google.com" runat="server" />

显然这不会重定向您,但根据您的代码的作用,听起来您并不想要重定向...

I see several problems.

  1. You do not have any sort of click event setup on your hyperlink. You do have a "onmouseover" but based on MSDN's documentation there is no click event for that control.
  2. You have a button defined, but no events associated with that button.
  3. You have a function that appears to be an event handler, but the naming convention suggests that it is associated with the button that has no events.

Can you provide more detail of what you are trying to do? I assume the c# code you have posted resides in the code behind?

Update:

Try changing your code to this -

<asp:LinkButton ID="lb_Link" OnClick="btnSubmit_Click" Text="www.google.com" runat="server" />

Obviously this will not redirect you, but based on what your code does, it doesn't sound like you want a redirect...

此生挚爱伱 2025-01-13 14:20:51

您尝试触发的事件是服务器端事件。您需要使用客户端代码来完成您想做的事情。另外,没有称为 onmouseover 的属性,您可以从后面的代码将其添加为客户端事件

HyperLink1.Attributes.Add("onmouseover","yourClientFunction");//this can be done in page load

The event you're trying to trigger is a server side event. You need to use client side code for what you want to do. Plus, there is no property known as onmouseover, you can add it as a client side event from code behind

HyperLink1.Attributes.Add("onmouseover","yourClientFunction");//this can be done in page load
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文