c# - asp.net and javascript please advise -
i new javascript , having problems.
my mission create mouseover , mouseout script having difficulty with,
my aspx code
<div> <div id="div_img" style="height: 300px; width: 300px; border: solid 1px black; position: absolute; visibility: hidden;"> <img src="" id="img_tool" /> </div> </div> <script type="text/javascript" language="javascript"> function showtooltip(con) { console.log(getoffset(con).left + '-' + getoffset(con).top); document.getelementbyid("div_img").style.visibility = "visible"; document.getelementbyid("img_tool").src = con.src; document.getelementbyid("div_img").style.left = getoffset(con).left - 300 + 'px'; document.getelementbyid("div_img").style.top = getoffset(con).top - 300 + 'px'; document.getelementbyid("div_img").style.zindex = "0"; console.log(document.getelementbyid("div_img").style.left +'-'+document.getelementbyid("div_img").style.top) } function hidetooltip() { document.getelementbyid("div_img").style.visibility = "hidden"; } function getoffset( el ) { var _x = 0; var _y = 0; while( el && !isnan( el.offsetleft ) && !isnan( el.offsettop ) ) { _x += el.offsetleft - el.scrollleft; _y += el.offsettop - el.scrolltop; el = el.offsetparent; } return { top: _y, left: _x }; } </script>
and code behind c#
if ((e.row.rowtype.tostring() != "header") && (e.row.rowtype.tostring() != "footer")) { imagebutton ib = (imagebutton)e.row.cells[3].controls[0]; ib.attributes.add("onmouseover", "showtooltip(this);"); ib.attributes.add("onmouseout", "hidetooltip();");
i have no idea next.. please
you can directly add these events img_tool
in aspx :
<img src="" id="img_tool" onmouseover="showtooltip(this);" onmouseout="hidetooltip();" />
plus, if want access controls (web controls or html elements) in code behind, have add attribute runat="server"
:
<img src="" id="img_tool" runat="server"/>
Comments
Post a Comment