Blog Reader RSS LoveCherry 技术无极限 GEO MVP MS Project开源技术
posted @ 2008-05-04 17:04 大宋提刑官 阅读(72) 评论(0) 编辑
posted @ 2008-04-10 09:55 大宋提刑官 阅读(362) 评论(0) 编辑

如果父div的position定义为relative,子div的position定义为absolute,那么子div的style.left的值是相对于父div的值,
这同offsetLeft是相同的,区别在于:
1. style.left 返回的是字符串,如28px,offsetLeft返回的是数值28,如果需要对取得的值进行计算,
还用offsetLeft比较方便。
2. style.left是读写的,offsetLeft是只读的,所以要改变div的位置,只能修改style.left。
3. style.left的值需要事先定义,否则取到的值为空。而且必须要定义在html里,我做过试验,如果定义在
css里,style.left的值仍然 为空,这就是我刚开始碰到的问题,总是取不到style.left的值。

offsetLeft则仍然能够取到,无需事先定义div的位置。

// 这个函数是对 一个无穷分类的 下拉框的操作,页面开始只有一个下拉框,当选中下拉框一个值后,
动态生成一个select, select的项是子分类,同时要使子分类的select框后移 20px;

 

Code

 {      $('itemtree_parentid').value = selectObj.value;      

  var level = parseInt( selectObj.level ); // 当前选中的分类的下拉框是第几层      

var left = parseInt( selectObj.offsetLeft ); // 取得左位置值      

var td = $('itemtree_cats'); // 分类容器      

var objs = td.getElementsByTagName( 'SELECT' );      // 去掉当前选中下拉框的所有子分类的下拉框      

for( var c=0; c<objs.length; c++ )

 {        if( parseInt(objs[c].level) > level )  

        td.removeChild( objs[c] );        }    

  // 重新生成一下子下拉框     

 var new_select = document.createElement('SELECT');      

new_select.onchange = function() 

{ itemtree_cats_change(this); };      

new_select.level = level + 1;     

 new_select.style.position = 'relative';      

new_select.style.left = (left + 20) + 'px';      // 不能给offsetLeft赋值,是只读的属性      

td.appendChild(new_select);    

posted @ 2008-08-11 09:28 大宋提刑官 阅读(1741) 评论(0) 编辑
一直以为offsetParent和parentElement是一回事,最近在做web控件才发现原来的理解是大错特错。
 
 parentElement 在msdn的解释是Retrieves the parent object in the object hierarchy.
 
 而offsetParent在msdn的解释是Retrieves a reference to the container object that defines the offsetTop and offsetLeft properties of the object. 这个解释有些模糊。我们再来看看他的remarks
 
 Most of the time the offsetParent property returns the body object.
 
 大多说offsetParent返回body
 
 
 Note  In Microsoft® Internet Explorer 5, the offsetParent property returns the TABLE object for the TD object; in Microsoft® Internet Explorer 4.0 it returns the TR object. You can use the parentElement property to retrieve the immediate container of the table cell.
 
 对于IE 5.0以上,TD的offsetParent返回Table。
 
 但是msdn并没有讨论在页面td元素中存在绝对/相对定位时offsetParent的值。
 
 以下是我个人总结的规律
 
 在td中的元素会把第一个绝对/相对定位的hierarchy parent当作offsetParent,如果没有找到需要分三种情况讨论
 
   一,如果该元素没有绝对/相对定位,则会把td当作offsetParent
 
   二,如果该元素绝对/相对定位并且table没有绝对/相对定位,则会把body当作offsetParent
 
   三,如果该元素绝对/相对定位并且table绝对/相对定位,则会把table当作offsetParent
 
 看一下示例代码
 
 1.<BODY >
 <TABLE BORDER=1 ALIGN=right>
   <TR>
     <TD ID=oCell><div id="parentdiv" style="position:relative" >parentdiv<div id="sondiv">sondiv</div></div></TD>
   </TR>
 </TABLE>
 
 
 运行结果parentdiv.offsetParent.tagName IS "body"
 
                 sondiv.offsetParent.id     IS "parentdiv"
 
 2.<BODY >
 <TABLE BORDER=1 ALIGN=right>
   <TR>
     <TD ID=oCell><div id="parentdiv" style="position:relative" >parentdiv<div id="sondiv" style="position:relative">sondiv</div></div></TD>
   </TR>
 </TABLE>
 
 运行结果parentdiv.offsetParent.tagName IS "body"
 
                 sondiv.offsetParent.id     IS "parentdiv"
 
 3.<BODY >
 <TABLE BORDER=1 ALIGN=right>
   <TR>
     <TD ID=oCell><div id="parentdiv" >parentdiv<div id="sondiv" style="position:relative">sondiv</div></div></TD>
   </TR>
 </TABLE>
 
 
 运行结果parentdiv.offsetParent.tagName IS "TD"
 
                 sondiv.offsetParent.tagName    IS "body"
 
 4.<BODY >
 <TABLE BORDER=1 ALIGN=right>
   <TR>
     <TD ID=oCell><div id="parentdiv" >parentdiv<div id="sondiv">sondiv</div></div></TD>
   </TR>
 </TABLE>
 
 
 运行结果parentdiv.offsetParent.tagName IS "TD"
 
                 sondiv.offsetParent.tagName    IS "TD"
 
 5.<BODY >
 <TABLE BORDER=1 ALIGN=right style="position:relative">
   <TR>
     <TD ID=oCell><div id="parentdiv" style="position:relative" >parentdiv<div id="sondiv" style="position:relative">sondiv</div></div></TD>
   </TR>
 </TABLE>
 
 运行结果parentdiv.offsetParent.tagName IS "Table"
 
                 sondiv.offsetParent.tagName    IS "parentdiv"
posted @ 2008-08-11 09:11 大宋提刑官 阅读(1229) 评论(0) 编辑
ObjectDataSource.Selected Event
Occurs when a Select operation has completed.
Code

Code
posted @ 2008-07-09 12:40 大宋提刑官 阅读(270) 评论(2) 编辑

Sets the Culture and UICulture for the current thread of the page.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

Code

How to: asp.net web localization by extending Page class.
部分代码:
Code

Code

The menu will be created using a simple inline foreach loop:

Code

posted @ 2008-07-09 08:36 大宋提刑官 阅读(382) 评论(0) 编辑

The ASP.NET configuration API allows you to develop, deploy, and manage application configuration data by using a single programming interface. Using the configuration API, you can develop and modify complete ASP.NET configurations programmatically without directly editing the XML in the configuration files. In addition, you can use the configuration API in console applications and scripts that you develop, in Web-based management tools, and in MMC snap-ins.

ASP.NET Configuration API Overview

Provides conceptual information about the .NET Framework classes that allow you to programmatically configure an ASP.NET application.

Using the Configuration Classes

Provides conceptual information about using the configuration classes in various configuration scenarios such as accessing global configuration data, accessing local configuration data, accessing remote configuration data, updating configuration settings, and the privileges required for each scenario.

How to: Access ASP.NET Configuration Settings Programmatically

Provides a code example that demonstrates the generic tasks involved in reading configuration settings.

How to: Read Application Settings from the Web.config File

Provides a code example that demonstrates how to read the appSettings configuration section.

How to: Read Connection Strings from the Web.config File

Provides a code example that demonstrates how to read the connectionStrings configuration section.

How to: View Inherited and Local Configuration Settings Programmatically

Provides a code example that demonstrates how to obtain a configuration file that contains all the configuration settings at a particular node, including those that are inherited.

Classes Used to Create Custom Section Handlers

Provides a list of .NET Framework classes that can be used to implement, configure, and use your own configuration section handler.

How to: Create Custom Configuration Sections Using ConfigurationSection

Provides a code example to describe how to implement, configure, and use a simple configuration section handler by inheriting the ConfigurationSection class.

How to: Create Custom Configuration Sections Using IConfigurationSectionHandler

Provides a legacy code example to describe how to implement, configure, and use a simple configuration section handler by implementing the IConfigurationSectionHandler class.

HTTP Module Configuration Sample

Provides a complete code example that demonstrates how to programmatically configure the httpModules element of a Web-application configuration using the HttpModulesSection class and related types.

ASP.NET Configuration Settings

Provides reference documentation for each of the configuration settings for ASP.NET applications.

General Configuration Settings (ASP.NET)

Provides reference documentation for general .NET Framework configuration settings that also apply to ASP.NET applications.

Using IIS Programmatic Administration

Provides information about how to use ADSI, WMI, and other technologies to configure IIS features.

posted @ 2008-07-08 15:40 大宋提刑官 阅读(183) 评论(0) 编辑

链接地址:http://msdn.microsoft.com/en-us/library/system.web.caching.cacheitemremovedcallback.aspx
Defines a callback method for notifying applications when a cached item is removed from the Cache.

 1<html>
 2 <Script runat=server language="C#">
 3    static bool itemRemoved = false;
 4    static CacheItemRemovedReason reason;
 5    CacheItemRemovedCallback onRemove = null;
 6
 7    public void RemovedCallback(String k, Object v, CacheItemRemovedReason r){
 8      itemRemoved = true;
 9      reason = r;
10    }

11
12    public void AddItemToCache(Object sender, EventArgs e) {
13        itemRemoved = false;
14
15        onRemove = new CacheItemRemovedCallback(this.RemovedCallback);
16
17        if (Cache["Key1"== null)
18          Cache.Add("Key1""Value 1"null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.High, onRemove);
19    }

20
21    public void RemoveItemFromCache(Object sender, EventArgs e) {
22        if(Cache["Key1"!= null)
23          Cache.Remove("Key1");
24    }

25 </Script>
26 <body>
27  <Form runat="server">
28   <input type=submit OnServerClick="AddItemToCache" value="Add Item To Cache" runat="server"/>
29   <input type=submit OnServerClick="RemoveItemFromCache" value="Remove Item From Cache" runat="server"/>
30  </Form>
31  <% if (itemRemoved) {
32        Response.Write("RemovedCallback event raised.");
33        Response.Write("<BR>");
34        Response.Write("Reason: <B>" + reason.ToString() + "</B>");
35     }

36     else {
37        Response.Write("Value of cache key: <B>" + Server.HtmlEncode(Cache["Key1"as string+ "</B>");
38     }

39  %>
40 </body>
41</html>
posted @ 2008-06-02 21:22 大宋提刑官 阅读(269) 评论(0) 编辑
posted @ 2008-05-21 15:12 大宋提刑官 阅读(603) 评论(0) 编辑
posted @ 2008-05-20 14:38 大宋提刑官 阅读(37) 评论(0) 编辑
posted @ 2008-05-19 16:33 大宋提刑官 阅读(112) 评论(2) 编辑