zoukankan      html  css  js  c++  java
  • asp.net3.5 csharp: How to show HTML content in calendar tooltip?

    from: http://dotnet.itags.org/web-forms/133110/

    csharp代码
      1 <% Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
      2 
      3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
      4 <html xmlns="http://www.w3.org/1999/xhtml">
      5 <head runat="server">
      6 <title>geovindu</title>
      7 <style type="text/css">
      8 #dhtmltooltip{
      9 position: absolute;
     10  150px;
     11 border: 2px solid black;
     12 padding: 2px;
     13 background-color: lightyellow;
     14 visibility: hidden;
     15 z-index: 100;
     16 /*Remove below line to remove shadow. Below line should always appear last within this CSS*/
     17 filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);
     18 }
     19 </style>
     20 
     21 </head>
     22 <body>
     23 <div id="dhtmltooltip"></div>
     24 <script type="text/javascript">
     25 
     26 /***********************************************
     27 * Cool DHTML tooltip script- ? Dynamic Drive DHTML code library (www.dynamicdrive.com)
     28 * This notice MUST stay intact for legal use
     29 * Visit Dynamic Drive athttp://www.dynamicdrive.com/ for full source code
     30 ***********************************************/
     31 
     32 var offsetxpoint=-60 //Customize x offset of tooltip
     33 var offsetypoint=20 //Customize y offset of tooltip
     34 var ie=document.all
     35 var ns6=document.getElementById && !document.all
     36 var enabletip=false
     37 if (ie||ns6)
     38 var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
     39 
     40 function ietruebody(){
     41 return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
     42 }
     43 
     44 function ddrivetip(thetext, thecolor, thewidth){
     45 if (ns6||ie){
     46 if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
     47 if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
     48 tipobj.innerHTML=thetext
     49 enabletip=true
     50 return false
     51 }
     52 }
     53 
     54 function positiontip(e){
     55 if (enabletip){
     56 var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
     57 var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
     58 //Find out how close the mouse is to the corner of the window
     59 var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
     60 var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
     61 
     62 var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
     63 
     64 //if the horizontal distance isn't enough to accomodate the width of the context menu
     65 if (rightedge<tipobj.offsetWidth)
     66 //move the horizontal position of the menu to the left by it's width
     67 tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
     68 else if (curX<leftedge)
     69 tipobj.style.left="5px"
     70 else
     71 //position the horizontal position of the menu where the mouse is positioned
     72 tipobj.style.left=curX+offsetxpoint+"px"
     73 
     74 //same concept with the vertical position
     75 if (bottomedge<tipobj.offsetHeight)
     76 tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
     77 else
     78 tipobj.style.top=curY+offsetypoint+"px"
     79 tipobj.style.visibility="visible"
     80 }
     81 }
     82 
     83 function hideddrivetip(){
     84 if (ns6||ie){
     85 enabletip=false
     86 tipobj.style.visibility="hidden"
     87 tipobj.style.left="-1000px"
     88 tipobj.style.backgroundColor=''
     89 tipobj.style.width=''
     90 }
     91 }
     92 
     93 document.onmousemove=positiontip
     94 
     95 </script>
     96 
     97 <form id="form1" runat="server">
     98 <div>
     99 <asp:Calendar ID="Calendar1" runat="server" OnDayRender="Calendar1_DayRender" ToolTip="werwerwer">
    100 </asp:Calendar>
    101 <a href="http://reference.itags.org/reference/link/?url=http://yahoo.com" onMouseover="ddrivetip('Yahoo\'s Site', 'yellow', 250)";
    102 onMouseout="hideddrivetip()">Yahoo</a>
    103 
    104 </div>
    105 </form>
    106 </body>
    107 </html>
    108 
    109 using System;
    110 using System.Data;
    111 using System.Configuration;
    112 using System.Web;
    113 using System.Web.Security;
    114 using System.Web.UI;
    115 using System.Web.UI.WebControls;
    116 using System.Web.UI.WebControls.WebParts;
    117 using System.Web.UI.HtmlControls;
    118 
    119 public partial class _Default : System.Web.UI.Page
    120 {
    121 protected void Page_Load(object sender, EventArgs e)
    122 {
    123 
    124 
    125 }
    126 protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    127 {
    128 
    129 string url= e.SelectUrl;
    130 e.Cell.Controls.Clear();
    131 
    132 HyperLink link = new HyperLink();
    133 link.Text = e.Day.Date.ToString();
    134 link.NavigateUrl = url;
    135 
    136 link.Attributes.Add("onMouseOver""ddrivetip('2333', 'yellow', 250)");
    137 link .Attributes .Add ("onMouseOut","hideddrivetip()");
    138 
    139 e.Cell.Controls.Add(link);
    140 
    141 }
    142 }

     Demo: http://www.dusystem.com/Calendar.aspx

  • 相关阅读:
    OutputCache详解
    C#数值类型的转换
    C#变量类型转换
    C#和.net
    数组
    mvc
    C#部分基础知识
    项目开发-->高级功能汇总
    项目开发-->基础功能汇总
    C#基础篇
  • 原文地址:https://www.cnblogs.com/geovindu/p/1767824.html
Copyright © 2011-2022 走看看