Sunday, December 27, 2009

验证输入空间 - SharePoint Validation Controls

The Microsoft.SharePoint.WebControls namespace of the Microsoft.SharePoint.dll contains a number of validation controls that can be used on application pages and web parts to validate user entry in the SharePoint controls.

The different validation controls are:

  • InputFormRequiredFieldValidator
  • InputFormRangeValidator
  • InputFormCompareValidator
  • InputFormRegularExpressionValidator
  • InputFormCheckBoxListValidator
  • InputFormCustomValidator

If you want to use these SharePoint control validators, you have to add a page directive to the page:

<%@ Register TagPrefix="spuc" Namespace="Microsoft.SharePoint.WebControls"              Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

The following sections describe the use of the different SharePoint validation controls.

The InputFormRequiredFieldValidator control

This control inherits from the standard ASP.NET RequiredFieldValidator and has the same functionality.

inputformrequiredfieldvalidator


Properties inherited from the standard ASP.NET RequiredFieldValidator control:

  • ControlToValidate: This property is required and must contain the id of the control to which this validator control applies.
  • ErrorMessage: This property contains the error message that will be displayed when the validation fails.
  • SetFocusOnError: When this property is set to true, the focus is set on the control that caused the validation to fail.
  • EnableClientScript: Setting this property to false will bypass client-side validation.

Important properties of the SharePoint InputFormRequiredFieldValidator control:

  • Display: This property influences the postion of the subsequent controls. If set to Static, the necessary space for the error message will be foreseen. Possible values are None, Dynamic and Satic.
  • ErrorImageUrl: If this property is filled out, the image will be displayed together with the error message in case a validation error occurs.
  • BreakAfter: When this property is set to true, a linke break is inserted after the error message.
  • BreakBefore: When this property is set to true, a line break is inserted before the error message.

The InputFormRangeValidator control

This control inherits from the standard ASP.NET RangeValidator control and has the same functionality.

inputformrangevalidator


Properties inherited from the standard ASP.NET RangeValidator control:

  • ControlToValidate: This property is required and must contain the id of the control to which this validator control applies.
  • Type: indicates the type of data to validate. If this property is omitted, the default is String.
  • MinimumValue: the lower boundary. The minimum value itself is considered as a valid entry.
  • MaximumValue: the upper boundary. The maximum value itself is considered as a valid entry.
  • ErrorMessage: This property contains the error message that will be displayed when the validation fails.
  • SetFocusOnError: When this property is set to true, the focus is set on the control that caused the validation to fail.
  • EnableClientScript: Setting this property to false will bypass client-side validation.

Important properties of the SharePoint InputFormRangeValidator control:

  • Display: This property influences the postion of the subsequent controls. If set to Static, the necessary space for the error message will be foreseen. Possible values are None, Dynamic and Satic.
  • ErrorImageUrl: If this property is filled out, the image will be displayed together with the error message in case a validation error occurs.
  • BreakAfter: When this property is set to true, a linke break is inserted after the error message.
  • BreakBefore: When this property is set to true, a line break is inserted before the error message.

The InputFormCompareValidator control

This control inherits from the standard ASP.NET CompareValidator control and has the same functionality.

inputformcomparevalidator





Properties inherited from the standard ASP.NET CompareValidator control:

  • ControlToValidate: This property is required and must contain the id of the control to which this validator control applies.
  • ControlToCompare: This property is required and must contain the id of the control against which the first control must be validated.
  • Type: indicates the type of data to validate. If this property is omitted, the default is String.
  • Operator: This property specifies the comparison operation. Possible values are Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, DataTypeCheck.
  • ErrorMessage: This property contains the error message that will be displayed when the validation fails.
  • SetFocusOnError: When this property is set to true, the focus is set on the control that caused the validation to fail.
  • EnableClientScript: Setting this property to false will bypass client-side validation.

Important properties of the SharePoint InputFormCompareValidator control:

  • Display: This property influences the postion of the subsequent controls. If set to Static, the necessary space for the error message will be foreseen. Possible values are None, Dynamic and Satic.
  • ErrorImageUrl: If this property is filled out, the image will be displayed together with the error message in case a validation error occurs.
  • BreakAfter: When this property is set to true, a linke break is inserted after the error message.
  • BreakBefore: When this property is set to true, a line break is inserted before the error message.

It is slightly different if you want to validate a date entered in a SharePoint DateTimeControl. This control is a composite control and you have to validate the date entered in the Date control:


I got the milk from Greg Galipeau’s blog in his post about validating an DateTimeControl with a standard ASP.NET Compare validator.

The InputFormRegularExpressionValidator control

This validator control can be used to validate user input against a regular expression. It inherits from the standard ASP.NET RegularExpressionValidator. Following example checks wether the user entered a valid email address.

inputformregexvalidator


Properties inherited from the ASP.NET RegularExpressionValidator control:

  • ControlToValidate: This property is required and must contain the id of the control to which this validator control applies.
  • ValidationExpression: contains the regular expression against which the user entry must be validated.
  • ErrorMessage: This property contains the error message that will be displayed when the validation fails.
  • SetFocusOnError: When this property is set to true, the focus is set on the control that caused the validation to fail.
  • EnableClientScript: Setting this property to false will bypass client-side validation.

Important properties of the SharePoint InputFormRegularExpressionValidator control:

  • Display: This property influences the postion of the subsequent controls. If set to Static, the necessary space for the error message will be foreseen. Possible values are None, Dynamic and Satic.
  • ErrorImageUrl: If this property is filled out, the image will be displayed together with the error message in case a validation error occurs.
  • BreakAfter: When this property is set to true, a linke break is inserted after the error message.
  • BreakBefore: When this property is set to true, a line break is inserted before the error message.

The InputFormCheckBoxListValidator control

This validator control can only be used against an InputFormCheckBoxList control (and not against an InputFormCheckBox control). It works as a required field validator: if no options are selected when clicking the OK button, the specified error message will appear:

inputformcheckboxvalidator







If you try to use it in combination with a InputFormCheckBox control, you will get an unclear error message (not informing you about the real problem) but when looking with Reflector into the code, it learns you that the control referenced in the ControlToValidate property is casted to an InputFormCheckBoxList control.

The InputFormCustomValidator control

If one of the previous validation controls does not suit your needs, you can define a custom validation function. You have the choice to define a client-side validation function or a server-side validation function, or combine both. Best practice is to perform server-side validation, even if you use a client-side check because some smartasses can try to bypass your client-side script.

inputformcustomvalidator-serverside

This is an example of server-side validation:


In your code-behind you define the controls as protected class-level variables:

protected InputFormTextBox UsernameTextBox;
protected InputFormCustomValidator UsernameCustomValidator;

And you add the server-side validation method. This method accepts 2 incoming arguments: a source object being the control to validate, and a args object having properties as Value and IsValid. The Value property contains the value to validate. Set the IsValid property to true if the validation is successful or set the IsValid property to false if the validation fails.

protected void ValidateUserName(object source, ServerValidateEventArgs args)
{
if (args.Value.Length >= 10)
args.IsValid = true;
else
args.IsValid = false;
}

Properties inherited from the ASP.NET CustomValidator control:

  • ControlToValidate: This property is required and must contain the id of the control to which this validator control applies.
  • ClientValidationFunction: contains the name of the javascript function that needs to be executed.
  • OnServerValidate: contains the name of the server-side function that needs to be executed.
  • ErrorMessage: This property contains the error message that will be displayed when the validation fails.
  • SetFocusOnError: When this property is set to true, the focus is set on the control that caused the validation to fail.
  • EnableClientScript: Setting this property to false will bypass client-side validation.

A lot of people combine a custom validator control with a RequiredFieldValidator but this is not necessary because the ASP.NET CustomValidator control (and thus also the InputFormCustomValidator control) has a ValidateEmptyText property which can be set to true or false. If set to false, a blank entry is validated as a valid entry. If set to true, a blank entry will be considered as erroneous, thus excluding the need for a RequiredFieldValidator control.

If you want to use client-side validation, you have to set the ClientValidationFunction property. The value must be the name of a javascript function.

inputformcustomvalidator-clientside


The javascript function must reside in the placeholder with ContentPlaceHolderID PlaceHolderMain (where most of your controls reside). The function needs 2 arguments: a source object, being the control that needs validation; and an arguments object having properties like Value and IsValid. If you want the validation to succeed, you have to set args.IsValid to true; if you want the validation to fail, you have to set args.IsValid to false.




Important properties of the SharePoint InputFormCustomValidator control:

  • Display: This property influences the postion of the subsequent controls. If set to Static, the necessary space for the error message will be foreseen. Possible values are None, Dynamic and Satic.
  • ErrorImageUrl: If this property is filled out, the image will be displayed together with the error message in case a validation error occurs.
  • BreakAfter: When this property is set to true, a linke break is inserted after the error message.
  • BreakBefore: When this property is set to true, a line break is inserted before the error message.

ValidationSummary control

You can combine any SharePoint validation control with the ASP.NET ValidationSummary control. There is no counterpart for it in SharePoint.

When you use no ValidationSummary control, all error messages appear next to or right under the control that fails validation. A ValidationSummary control presents the user with a lsit of validation errors at the bottom of the page.

validationsummary

You add a ValidationSummary control to your application page or web part as follows:

The different propeties on the ValidationSummary control are:

  • DisplayMode: this property defines the appearance of the summary. Possible values are List, BulletList and SingleParagraph.
  • HeaderText: set this property if you want to display a header text at the top of the summary.
  • ShowSummary: set this property to show the error summary on the page. In that case the ShowMessageBox property must be set to false.
  • ShowMessageBox: this property indicates whether the validation summary is displayed in a message box or on the page. In that case also the EnableClientScript property should be set to true.

Normally you should also be able to set the Text property of the SharePoint validation controls to f.e. * to display an asterisk next to the control that failed validation but after a look inside the Microsoft.SharePoint.dll with Reflector it show that the Text property is overridden and looses its original meaning.



向SharePoint 延伸 Global.asax - Extending SharePoint using Global.asax

Have you ever wanted to do stuff with SharePoint sites that webparts just won't let you do? Here are a few things that I wanted to do in SharePoint that I knew I couldn't really do with WebParts or custom pages.

  • Better stats - the built-in stats are ok, but I want some better stats.
  • Register Users - I want everyone to have access to the site, but I would like to collect a little information about them before I give them access.

For this article I will just tackle the task of getting better stats about SharePoint usage, but you can easily apply the methods I use to do all kinds of things in your SharePoint application.

First off, you will need to do a little background reading on Global.asax (if you aren't already familiar with it). The Global.asax file allows you to write code against events that happen within an ASP.Net application. SharePoint is no different so you can write custom code and stick it in the Global.asax file and gain more control over your application.

Below is a quick and dirty solution for capturing information about how people are using your SharePoint site (or portal). Of course you can use the built in stats, however, I personally find those stats to be somewhat limited. The method below captures the URL the person went to, the timestamp of the request, and the UserID. What you can do is to add this code to a file called Global.asax and place it in the root directory of your site.

<%@ Application ClassName="Globals" language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>

Before you can use the script you will also need to create a table and a stored procedure to populate the table. Below is the SQL script to create both. You will need to put them in a custom database (I would not recommend putting them in one of the SharePoint databases).

create table [Hits]
(
Url varchar(256) NOT NULL,
UserID varchar(50) NOT NULL,
Timestamp datetime NOT NULL
)
go
create proc Hit_Add
(
@Url varchar(256),
@UserID varchar(50)
)
as
insert into Hits values
(@Url, @UserID, getdate())

go

That's all there is to it. The AuthenticateRequest Event gets fired each time the user makes a request to the site. You make the call to the database here because in the BeginRequest event the user hasn't been authenticated yet. I'm not sure but I believe this is different from normal ASP.Net applications due to the way SharePoint handles the request.

I'm sure you can think of many other ways that this will be useful. I'll be looking forward to your comments and suggestions.

Monday, May 18, 2009

广东话常用字拼音输入方法 分享

嘅 咗 冇 係 睇 唔 咩 啲 咁
唔识 唔知 而家 边度 边个 冇问题 识听 识讲 有冇搞错 靚唔靚 得唔得

嘅嘢(ge)=…的东西
乜(mie)= 什么; 例如:你有乜?=你有什么?
冇(mao)= 没有;例如:有冇钱?=有没有钱?
甴曱(gad zad)= 蟑螂
叻(le/ li)= 很棒;例如:佢啲成绩好叻啵=他的成绩很厉害呵
冚(hem)= 全部?;例如:冚家铲=全家死光光
氹(dang)= 哄;例如:氹你开心=哄你开心
佢(qu)= 他或她;例如:佢系边个?=他是谁?
呃(e)= 骗;例如:呃神骗鬼
抦(bing)= 殴打;例如:我哋去抦果条友=我们去揍那个家伙
拎(lin)= 提、 拿
拗(ao)= 矛盾; 例如: 拗交=吵架
咁(gan)= 如此、这样;例如:咁啊?=这样啊?
咗(zo/ zuo)= 了;例如:食咗饭未?=吃了饭没有?
呢(ne)= 这;例如:呢啲事=这些事
哩(li)解释同上
乸(na)= 雌性;例如:鸡乸=母鸡?
哋(dei/ mi) = 们;例如:我哋=我们
咦(yi)= 感叹词,啊(表奇怪); 例:咦?
噫 (yi)解释同上
咯(lo)= 语气助词
咩(mie) = 什么;例如:有咩事?=有什么事?
咪(mi)= 不要; 例如:咪走~=不要走~~
系(xi)= 是; 例如:系乜嚟架?=是什么东*来的?
吊(diao)= ...
唓(che)= 语气助词,表示鄙夷
哽(geng)=当然;例如:哽系=当然是
唔(en、wu)= 不;例如:唔系=不是
俾(bi) = 给; 例如:你俾我啦~=你给我吧
冧(min)= 哄、陶醉;例如:佢冧我/要冧吓佢=她喜欢我/要哄一下她
屙(e)= 排泄;例如:屙尿=拉尿
掂(dian)= 完结或状态佳之意;例如:搞掂=办妥
掟(ding) = 扔
啫(ze)= 语气助词;例如:唔系啫=不是的
啱(ngam)= 对、合适、恰巧;例如:啱心水=合心意
啰(luo)= 语气助词/啰嗦
谂(shen)= 想;例如:我谂咁做唔好嘎?=我想这样做不好吧?
啖(dan)= 口;例如:咬一啖=咬一口
啵(bo) = 语气助词
靓(liang)= 漂亮或表示幼稚; 例如: 靓仔=帅哥/小子
揾(wen)= 找、挣;例如:揾食=谋生
睇(ti/ di)= 看;例如:睇电视=看电视
啲(di)= 的、少许;例如:俾啲钱佢=给一点钱他
嗟(jue)= 语气助词,感叹声; 例如:嗟~好巴闭咩?=切~很了不起么?
嘅(ge)= 的;例如:你嘅道服呢?=你的道服呢?
喔(wo)= 语气助词l!
嘥(sai)= 语气助词 浪费
嗰(go)= 那;例如:嗰啲=那些
嘞(le)= 语气助词
嘢(ye)= 东*;例如:有嘢睇=有东*看
嘈(cao)= 吵;例如:嘈乜鬼=吵什么东
嘎(ga)= 语气助词;例如:唔系咁嘎~= 不是这样的
嗻(zhe)= 语气助词;例如:我先至23嗻=我才23呀
撇(pie)= 闪,走人
撩(liao)= 挑逗;例如:撩是斗非=惹是生非
瞓(fen)= 睡;例如:眼瞓=困顿
嬲(niao)= 生气/一向;例如:我好嬲/不嬲都喺咁嘅=我很生气/向来都是这样的
嚟(li)= 来;例如:入嚟=进来
攞(luo)= 拿;例如:攞嘢=拿东
囖(lo) 语气助词
吤(ge)例如:将啲橙搣开一吤吤(一片片)
咿(yi)例如:咿家去边啊?
惗(nie)想 例如:成日惗埋晒啲衰嘢
嘁(qi) 例如:嘁起条筋
嘚(de)
咖(ga)语气助词
嘎(ga)解释同上
嚿(geo)例如:大嚿衰
啱(ngam) 例如: 咁啱嘅
悭(qian) 省 例如: 悭钱
喺(bei)在的意思.例:你喺度做紧乜啊?=你在干什么啊? .
嗌(ai)吵、叫的意思.例:嗌架=吵架 嗌救命=叫救命 嗌喇,嗌喇,你嗌破喉咙都冇人理你架嘞
噏(xi)意思是说、讲.你噏乜啊?=你说什么啊?乱噏廿四 发噏疯
谂(shen)想的意思,跟惗同意,但广州话字嘅发源地–香港用惯呢只
咋(za)语气词,意思跟普通话的”而已”差不多.开玩笑咋,唔好咁认真啊=开玩笑而已,不要那么认真
梗(geng)当然,代替”哽”,香港惯用
窒(zhi)例:窒住晒
嗱(na)例:嗱,唔好话我唔提醒你啊
郁(yu)动.例:郁我吖笨

Friday, January 2, 2009

[教学] 快速 下载 youtube 影片 , 存档为 FLV video , RETRIEVE NOW


复制网址后,浏览以下网址

http://kej.tw/flvretriever/

,并将刚才所复制既网址如图中般贴上↓


然后按 RETRIEVE NOW !

之后就会得出↓当然你可以选择 save as a new file and then you can rename it as a .flv file 下载
想更快速,把URL放进 thunder 讯雷下,会更加快哦。

下载完后,记得rename 为 .flv 的档案,就可以播放了

如果你的电脑无法播放 请下载 安装 StormCodec6.08.13
请到下面的网址下载
http://www.gougou.com/search?search=StormCodec6.08.13&id=1

身分证字号自动随机网页产生, 台湾身份证, 中国身份证, 香港身份证, 韩国身份证

按这里 >> http://id.unet.cc/


身分证字号产生

自动随机产生

台湾身份证

中国身份证

香港身份证

韩国身份证

身分證字號產生

自動隨機產生

台灣身份證

中國身份證

香港身份證

韓國身份證

Thursday, January 1, 2009

大便无聊当有趣? the shit stream

大便无聊当有趣?
还真的有人开大便网站,好恶心哦,看下面
http://theshitstream.blogspot.com/

[教学]如何在BlogSpot提交Sitemap?

来源 http://weisue.pixnet.net/blog/post/20457732

最近又弄了一个部落格,结果之前该做的一些SEO差点又都忘光光
(这个算是入门的SEO了,连我都会,那就代表大家都能会)
干脆写篇文当作笔记吧
哪天说不定又会用到

使用的环境:Blogspot (就是Google的部落格服务)
预期提交的Sitemap的网站:Google Yahoo MSN

首先呢
你必须要有Google Yahoo及MSN的帐号(我想大家应该都有吧,不然申请一个也不是什么难事!)

先介绍Google吧!

Google篇
先进到这个网页吧
Google网站管理工具:https://www.google.com/webmasters/tools/docs/zh_TW/sitemap-generator.html
应该会看到这个画面


点选其中的『Google网站管理员中心』
就会看到这个画面了

应该知道要选哪一个吧
就是『网站管理员工具(包含Sitemaps)』


这样就可以看到你的控制主页了
如果你是第一次使用,里面就不会有网址了

再来就是在『网站』那个框框打入你的网址,点选『新增网站』
比如说我的网站是http://abc.blogspot.com

就会有下面的画面了

差不多了,再来就是『验证你的网站』
你必须告诉Google你是真的拥有这个网站的

要怎么证明你是这个网站的管理员呢
选取『新增中继标记』
然后把后面的程式码复制起来
等一下会用到喔!
PS:画面先别急着关喔!马上会用到!

Blogspot篇
现在就是要证明你真的拥有这个网站的时候了
进入Blogspot
这个画面应该很熟悉吧!
『版面配置』『修改HTML』
重点1:要点选『展开小装置范本』(为什么??我也不知道,不过大家都说要点!)
重点2:找到 (就在前面几行,不难找!)
重点3:把前面的那串『中继标记』贴到的下一行
然后点『储存范本』
这样你已经可以证明你拥有这个网站了


前面的那个有『中继标记』的页面还没关掉吧!
点『验证』
这样你就完成神圣的任务了吗? ?
当然没有

我们不是讲Sitemap吗
总是要新增个Sitemap吧


点选『新增』Sitemap

要提送什么样的Sitemap呢?选『新增一般网页Sitemap』
然后我的Sitemaps URL就打『atom.xml』 和 『atom.xml?redirect=false』
(为什么要打这个?我也不知道,应该是透过atom去订阅吧)
然后按『新增一般网页Sitemap』就大功告成了

这样『据说』Google就会自动去抓你的网页资料,并且列入他的搜寻资料里面了!
以后有人透过Google去搜寻某些关键字的时候,你的网页被搜寻到的机会就会大大提高喔!