0

笔记

  • 是的,客户端必须是 java 脚本,但我的问题不是这样。

  • 我在问我可以使用 c# 语言来实现在“单击侧事件”上触发的“动作”,例如鼠标悬停

  • 这个愚蠢问题的原因是我记得一些为formview的特定事件注册函数的语法,这些函数在事件发生时被调用(是的,涉及回发”

  • 对于使用 c# 甚至 vb.net 的客户端事件,可能类似于上述内容

这是我想问的一小部分

 protected void Page_Load(object sender, EventArgs e)
{



    Label3.Text = "this is label three";



    Label3.Attributes.Add("OnMouseOver", "testmouseover()");



}


protected void testmouseover()
{
    Label4.Text = "this is label 4 mouse is working!!";

}
4

3 回答 3

4

这是不可能的。

  • 您可以使用 AJAX,但不能使用 AJAX 直接操作 DOM。
  • 您可以使用 UpdatePanel,但不能(轻松)用于鼠标事件。
  • 您可以使用Script#,它将 C# 转换为 Javascript。
    但是,它与服务器端代码无关
于 2011-01-24T18:11:22.623 回答
1

ClientScript.RegisterClientScriptBlock() 有你需要的吗?在这里检查

于 2011-01-24T19:03:27.240 回答
0

您可以通过使用页面方法来做到这一点。

protected void Page_Load(object sender, EventArgs e)
{
    Label3.Text = "this is label three";
    Label3.Attributes.Add("OnMouseOver", "testmouseover()");
}

[webmethod]
public static void testmouseover()
{
    // Implement this static method

}

然后在客户端这样做:

<script type='javascript'>
function testmouseover()
{
    PageMethods.testmouseover();
}
</script>
于 2011-05-20T05:28:02.233 回答