asp.net - 从 CodeBehind 注册 OnMouseOver-Event?

标签 asp.net javascript

我不想从后面的代码为图像注册 OnMouseOver 和 OnMouseOut-Event,因为无论用户是否登录,我都必须有所不同。 有什么想法吗?

最佳答案

您可以向对象添加属性。

例如

 Image img = new Image();
 img.Attributes.Add("onmouseover", "myjavascriptfunction();");

要根据对象的 id 设置参数,使用:

 Image img = new Image();
 img.Attributes.Add("onmouseover", "myjavascriptfunction(" + img.ClientID + ");");

关于asp.net - 从 CodeBehind 注册 OnMouseOver-Event?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1713884/

相关文章:

c# - .NET 中的异常处理和日志记录策略

javascript - Angularjs、lexerr 词法分析器错误 : How to pass email address (regex) to a function

javascript - 导入的 React 组件具有不需要的宽度 : 0 div at root and is stopping the component fill the parents CSS grid area

javascript - IE8 中的控制台未定义问题

c# - 从 ASP.NET 下拉菜单重定向

c# - 内存压力会导致 ASP.NET 中的 session 数据逐出吗?

c# - 如何使用 Linq 检查 JSON 中的标签

javascript - 验证 gridview 中选定的下拉值并使用选定值填充标签

javascript - 如果是一个月的最后一天,如何使用 javascript 验证日期?

javascript - jQuery datepicker altFormat 不显示