Add Javascript to an usercontrol in c# -


i have 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"));            }         }     } 

this control simple, add reference , control page want use :

<%@ register src="controles/uctooltip.ascx" tagname="uctooltip" tagprefix="uctt" %> ... <uctt:uctooltip id="tooltip" runat="server" /> ...  

so, control loaded , script added page.

but trying more elaborate. given have lot control need tooltip, decided add event(it show , hide tooltip) usercontrol's base. usercontrol use inside main page (the tooltip accessible page).

first, have tried :

protected virtual void page_load(object sender, eventargs e) {    attributes.add("onmouseover", "alert('d')"); } 

on control's base page load, had attribute throw event "onmouseover" control.

but don't work, confuse why...

although usercontrol has attributes property, doesn't anything. instead, need put onmouseover attribute on element inside .ascx markup. example:

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

if need add attribute dynamically, make <div> runat="server" control can access attributes property code-behind file:

dhtmltooltip.attributes.add("onmouseover", "alert('d')"); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -