在C#中将Javascript添加到用户控件 - c#

我有一个UserControl,它是一个ToolTip

.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucTooltip.ascx.cs" Inherits="Portail.formulaires.ucTooltip" debug="true"%>


<div id="dhtmltooltip" style="z-index:9999999999; display:inline-block;">
  <div id="dhtmltooltip_title">

  </div>
  <div id="dhtmltooltip_content">

  </div>
</div>

.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace Portail.formulaires
    {
        public partial class ucTooltip : System.Web.UI.UserControl
        {
           protected void Page_Load(object sender, EventArgs e)
           {
              Page.ClientScript.RegisterClientScriptInclude("Hint", Page.ResolveUrl("~/Scripts/hint.js"));
           }
        }
    }

这个控件非常简单,我只需在要使用的页面上添加引用和控件即可:

<%@ Register src="Controles/ucTooltip.ascx" tagname="ucTooltip" tagprefix="ucTT" %>
...
<ucTT:ucTooltip ID="tooltip" runat="server" />
... 

因此,将加载控件并将脚本添加到页面。

但是我正在尝试做一些更详细的事情。鉴于我有很多需要工具提示的控件,因此我决定在用户​​控件的基础上添加Event(它将显示和隐藏工具提示)。所有用户控件都在我的主页中使用(可从此页面访问工具提示)。

首先,我尝试过类似的方法:

protected virtual void Page_Load(object sender, EventArgs e)
{
   Attributes.Add("OnMouseOver", "alert('d')");
}

在控件的基本页面加载中,我有一个属性可将事件“ OnMouseOver”抛出给控件。

但这不起作用,我很困惑为什么...

参考方案

尽管UserControl具有Attributes属性,但实际上不执行任何操作。相反,您需要将onmouseover属性放在.ascx标记内的元素上。例如:

<div id="dhtmltooltip" style="z-index:9999999999; display:inline-block;" onmouseover="alert('d')">

如果需要动态添加属性,则将<div>设置为runat="server"控件,以便可以从代码隐藏文件访问其Attributes属性:

dhtmltooltip.Attributes.Add("onmouseover", "alert('d')");

Div单击与单选按钮相同吗? - php

有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date&#…

调整窗口大小时如何调整YouTube播放器的大小 - php

我想显示包含YouTube视频的弹出窗口。我的问题是当用户调整弹出窗口的大小时如何调整YouTube播放器的大小?弹出窗口的头部分PHP / HTML代码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/…

将python scikit学习模型导出到pmml - python

我想将python scikit-learn模型导出到PMML。哪个python软件包最合适?我阅读了有关Augustus的内容,但是我无法使用scikit-learn模型找到任何示例。 python大神给出的解决方案 SkLearn2PMML是 JPMML-SkLearn命令行应用程序周围的薄包装。有关受支持的Scikit-Learn Estimator和…

如何使用PHP从动态输入字段捕获数组值? - javascript

我正在编写一个在线时间跟踪网页,允许用户将学习时间输入该系统。用户将首先输入名称,然后根据日期输入学习时间。一天中可能会有多个学习时间。以下是我第一页的编码,<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"…

SOAPFaultException部署在Tomcat上时,但在GlassFish中工作正常 - java

朋友们,我一直在尝试很多,阅读了很多论坛,但无法理解为什么出现此问题。我使用契约优先方法创建了一个Jax-WS WebService。创建WSDL和XSD,然后使用wsimport工具生成其余工件,为SEI提供实现。将WebService应用程序部署到Eclipse Helios中的GlassFish(Glassfish适配器和Eclipse中安装的插件)。…