How to set the location of CalendarExtender by the Mouse when clicking the page

Preface

Everytime we want to display the CalendarExtender at the client side, we need to use this code:

ContractedBlock.gif ExpandedBlockStart.gif Code
$find(“the calendar’s behaviorid”).show();

 

Text

How can we change the location of the Calendar as we wish?

Here is the solution:

ContractedBlock.gif ExpandedBlockStart.gif Code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestCalendarPosition.aspx.vb"
    Inherits
="SoluTest_CalendarUserControl.TestCalendarPosition" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title></title>

    
<script type="text/javascript">
    
        
//To handle the mouse up event
        function onMouseUp() {
            $find(
"cal").hide();
            $find(
"cal").show();
        }

        
//We need to change the position after the Calendar is shown.
        //To handle the client shown event
        function calendarShown() {
            
//If set a breakpoint here,you may notice that the style of the Calendar popup div would like this:
            //    "LEFT: 10px; VISIBILITY: visible; POSITION: absolute; TOP: 38px"
            //The current postion is the Target TextBox's position. Now, let's specify it.
            $get("cal_popupDiv").style.top = event.offsetY;
            $get(
"cal_popupDiv").style.left = event.offsetX;
        }
    
    
</script>

</head>
<body>
    
<form id="form1" runat="server" onmouseup="onMouseUp()" style="background-color: #FFFF99;
    width: 1000px; height: 1000px;"
>
    
<div>
        
<asp:ScriptManager ID="ScriptManager1" runat="server" />
        
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        
<cc1:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" BehaviorID="cal"
            Enabled
="True" TargetControlID="TextBox1" OnClientShown="calendarShown">
        
</cc1:CalendarExtender>
    
</div>
    
</form>
</body>
</html>

 

Comment

The cal_popupDiv document is the popup div of Calendar "cal", it can also be find by using

ContractedBlock.gif ExpandedBlockStart.gif Code
$find("cal")._popupDiv

Or

ContractedBlock.gif ExpandedBlockStart.gif Code
$find("cal")._popupBehavior._element

We need to check if it is null before using it.

Note

Note that I set the Calendar’s popup position as the Mouse’s offset position and it can only be used in IE, you can change it as your wish.

The related thread url:http://forums.asp.net/t/1373908.aspx

转载于:https://www.cnblogs.com/Zhi-QiangNi/archive/2009/01/27/1381062.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值