Friday, November 13

Disable button after sumit

Originally, an asp.net page has a button
< id="btnCreate" text="Create" runat="server" onclick="btnCreate_Click">
to fire the btnCreate_Click event.

The event takes a few seconds to perform its job, so the client complained that sometimes she clicked the button twice, and 2 items are created. "It would be better if the button is disabled after clicked".

Sure, we programmers can do that.

Adding "btnCreate.Enabled=flase" into the btnCreate_Click event can not do the trick, because this property will not be set until all the jobs in this event are performed and the new page is return to client's browser. A javascript applet must be activated to disable this button, when the form is being submitted into server and firing up the event.

How about adding javascript directly in this button like:
< id="btnCreate" text="Create" runat="server" onclick="btnCreate_Click" onclientclick= "
"this.value='Please wait...'; this.disabled = true; " + ClientScript.GetPostBackEventReference(btnCreate, string.Empty) + ";");
It worked perfectly for IE and Firefox 3.0, until the Firefox 3.5 was release in July 2009.

At this point, the HTML source of rendered page is like:
< input type="submit" name="ctl00$MainPageContent$btnCreate" value="Create" onclick="this.value='Please wait...'; this.disabled = true; ;__doPostBack('ctl00$MainPageContent$btnCreate','')" id="ctl00_MainPageContent_btnCreate" />

After July, I got reports saying duplicate items were generated at the same second. I collected all the Addons from the clients and literally added them into my Firefox (it was 3.0 because I didn't notice the version is playing an important role) one by one. After adding one Addon, I restarted the Firefox and visited the same page to click the button. After adding all 15 Addons, there is no duplicate items from my Firefox.
Finally the Firefox version number is located as the source of this issue. Paros and Firebug is deployed to catch the traffic. Only one post action from Firefox 3.5 fires up the btnCreate_Click event twice. That is so weird. Is that a bug in Firefox 3.5, or in Asp.NET?

I don't see any Googled page mentioned this problem, and there was no solution existed, until this blog is written.

Solution: Step 1, modify the button as
< id="btnCreate" text="Create" runat="server" onclick="btnCreate_Click" style="color: rgb(255, 0, 0);" usesubmitbehavior="false">
Step 2, modify the code in Page_Load as
btnCreate.Attributes.Add("onclick",
"this.value='Please wait...'; this.disabled = true; ");
After that, the HTML source of rendered page is almost the same:
< input type="button" name="ctl00$MainPageContent$btnCreate" value="Create" onclick="this.value='Please wait...'; this.disabled = true; ;__doPostBack('ctl00$MainPageContent$btnCreate','')" id="ctl00_MainPageContent_btnCreate" />



Analysis:
The description of UseSubmitBehavior from Microsoft
is very confusing:
Use the UseSubmitBehavior property to specify whether a Button control uses the client browser's submit mechanism or the ASP.NET postback mechanism. By default the value of this property is true, causing the Button control to use the browser's submit mechanism. If you specify false, the ASP.NET page framework adds client-side script to the page to post the form to the server.
Originally, the
UseSubmitBehavior is "true" by default, the HTML source is
< input type="submit" name="ctl00$MainPageContent$btnCreate" value="Create" />

If you have been reading the HTML source carefully, you can notice that the < input > of first HTML source is a "Submit", and the second < input > is a "Button". The UseSubmitBehavior decides the difference. My first solution added a javascript __doPostBack into a "Submit", and the Firefox 3.5 decides to submit the form twice, I guess.

The combination of local javascript and serverside script can be very fragile, so extra attention must be taken to deal with it.

Thursday, October 29

The Three Great Virtues

Recently I figured out I have the 3 great virtues of a programmer:

  1. Laziness - The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don't have to answer so many questions about it. Hence, the first great virtue of a programmer.
  2. Impatience - The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to. Hence, the second great virtue of a programmer.
  3. Hubris - Excessive pride, the sort of thing Zeus zaps you for. Also the quality that makes you write (and maintain) programs that other people won't want to say bad things about. Hence, the third great virtue of a programmer.

(Wiki)
My fellow people always ask me to be humble. I should have let them know: I am too pride to be humble!

Thanks for sharing, I'm also a shoe fans of Christian Louboutin.And I know
Christian Louboutin is famous for his skyscraper heels and styles that range from black patent stilettos to jewel-encrusted party shoes.Now I work for a company which sells Christian Louboutin shoes online.It's http://www.christianlouboutinshoesmart.com.If you have interest,you can come and see!
 

Ed2k Monitor

I shared /media/public/Incoming/waitinglist/ folder, so from other computers in the network user can create a text file with content of
ed2k:xxxxxxxxxxxxxxxxxxx
ed2k:xxxxxxxxxxxxxxxxx
This script will monitor this folder for any new text file and feed ed2k links into aMule:



#!/usr/bin/perl
#The purpose of this script is to monitor a directory periodically, and run ed2k (aMule) for new entries in this folder (then delete them).

#ben@fadshop.net. Jun 1, 2009.

# Version 2: Aug 11, 2009. Read each line of the files for importing.



# Edit Cronjob by:

# crontab -e

#0,15,30 * * * * script.sh

###or

#0-59/15 * * * * script.sh



# model: http://www.perlmonks.org/?node_id=283849

use strict;

use warnings;



sub printlog

{

my $logfile = shift;

my $logmessage = shift;

my $now = localtime time;

open(LOGFILE, ">>$logfile");
print LOGFILE $now . " " .$logmessage . "\n";

close LOGFILE;

}



sub scandir

{

my $dir = shift;

my $fileProcessor = shift;



opendir (DIR, $dir) or die "Cannot open $dir: $!\n";

while (my $filename = readdir(DIR))

{
next if $filename =~ /^\.\.?$/; # skip . and ..
if ($filename =~ /\.txt$/) {

&$fileProcessor("$dir/$filename");
}
if ($filename =~ /.torrent$/) {
`transmission "$filename"&`;
}

}

close DIR;

}





sub runed2k

{

my $filename = shift;
print "got file: $filename\n";
open(ED2KFILE, $filename);

foreach my $line (){
$line =~ s/\r(\n?)//;
if ($line =~ /^ed2k/){

`ed2k "$line"`;

#print LOG

printlog('/tmp/ed2klog', $line);
}
if ($line =~ /^http/){
chdir('/media/public/Incoming/');

`wget "$line"&`;

#print LOG

printlog('/tmp/ed2klog', $line);
}
}

close(ED2KFILE);
unlink($filename);

}







scandir('/media/public/Incoming/waitinglist',\&runed2k);



The result is: In any computer of my network, I can put the ed2k link into text file. The Linux server will retrieve the ed2k resource for me overnight.

Once upon a time, two women created the cutest velour hoodies and matching drawstring pants. The line was called Christian Louboutin and every starlet in Tinseltown had to have one. Soon after, so did the rest of the world. Now the once little brand has blossomed into a fashion empire, complete with clothing, Christian Louboutin Shoes, jewelry, handbags, and most recently, fragrance.
 

Wednesday, October 21

宗教和心理市场:生活助理市场上陌生供应商检测单

1、供应商所提供的,正是你很长时间以来寻找却没有找到的。很奇怪,他正好知道你
缺什么。

2、与供应商的第一次接触就为你看问题打开了全新的视线。

3、供应商的世界观非常简洁明了,能够借以解答一切问题。

4、供应商试图从情感上争取你,其他成员很快就成了你的“好朋友”。

5、你觉得提出批评性看法,那些新朋友会感到失望,而且,如果你总得拒绝新朋友不
断的邀请会觉得过意不去,因为你不愿意做一个不讲礼貌的人。

6、供应商越来越多地进入你的生活,逐渐形成一种引力:似乎进去容易出来难。

7、尽管如此,你还是不清楚供应商的情况。对你的要求是,不要思考,不要检验。你
的新朋友会说:“这没法解释,必须自己去体验,我们所经历的完全是另外一个层次…
…”或类似的说法。

8、供应商有一个拥有真理的大师或者是神的传话人,他的决定权不受任何怀疑。

9、供应商的教义被视为是唯一真确、永久正确的知识,拒绝传统的科学,拒绝理性思
维,拒绝理智,认为这些只重视脑,是负面的,是属于撒旦的等等。

10、供应商缺乏理性的讨论文化:因为供应商认为自己拥有不可改变的真理,所以认为
一切关于自己的教义和组织的讨论都是多余的。

11、供应商内部的批评者被诬陷、隔绝或开除。

12、来自供应商外的批评被当作供应商正确的证据。

13、供应商总感觉自己被敌对势力包围,外部的人都在对自己施展阴谋。

14、供应商只认识两种人:要么是朋友,要么就是敌人,谁不是我们的支持者,谁就是
我们的反对者。

15、世界面临着大灾难,只有供应商自己知道,如何让这世界或自己的信徒得救。

16、供应商内部的人是精英,外部的人都在走邪路,充其量是传教的争取对象。

17、供应商可以为了实现自己的目标不择手段。

18、供应商内部通过特别的标志或行为规则与其他人隔离开来,比如通过自己的语言、
特定的服装、饮食、对日常生活的控制和对私人关系的干涉。

19、供应商促使你与到目前为止的社会关系隔离,原因是这些社会关系影响你的进步。

20、供应商促使你把自己的信息来源局限于供应商自己的意识形态(不看新闻,不读报
纸,不读文学作品,只读供应商内部的读物)

21、供应商给你安排任务,要求你参加活动,占用你几乎所有的时间(比如卖书刊、参
加学习班、参加活动、祈祷、打坐、共同读书、拉新人入教)。

22、你很少一个人单独活动,总是有供应商的人来接你,或许你还被要求到供应商的集
体住处去住宿,对你的个人生活的控制被称为是对你坚持走唯一正路的支持。

23、供应商也为你做通常由每个人自己做的决定。

24、供应商公开或暗示性地要求你严格服从,甚至要求你放弃自我,因为这是取得进步
或得救的唯一途径。

25、如果你对供应商产生怀疑,不会有人关心你怀疑的原因,更多的是,你将会听到某
些现成的解释:这套体系本身没错,只是你还没到时候。如果你没能取得进步,那么原
因只在你自己,因为你信得不够,读得不够,理解得不够,祈祷不够,打坐不够或者是
上课上得不够等等。

26、有时候你会觉得这个供应商可怕,觉得自己受到了压力,可是你很快就排除这种念
头,并且尽力使自己更加靠近这个供应商。


从柏林市政府邪教事务专员2002年报告“都是邪教Sekte吗?——风险与副作用”第II部分第
8章“宗教和心理市场”摘译.报告把所有作为调查对象的团组称为“生活助理市场上容易引起冲突的供应商”,在涉及到宗教性质团组的检测单中只是说“供应商”。如果某教某派符合检测单中的一个以上特征,就要小心,这个教派就可能会给当事人在家庭生活、工作或/和个人心理等方面带来不同的麻烦,符合得更多,就应该更加小心。德文原文可在柏林市政府教育、青年与体育厅网页下载,网址是:
http://www.senbjs.berlin.de/familie/sog_sekten_psychogruppen/thema_sog_sekten.asp (点击"Alles Sekte - oder was?"下载PDF文件)

=========

摘录自 乡下人进城

If you are headed to a big party or other special occasion, these Christian Louboutin Ice sandals definitely fit the bill. Wear these Christian Louboutin with a black outfit for big time drama. The Louboutin feature cut-outs around the peep-toe, a buckle closure on the slingback and a 3-inch wrapped heel. You can order these Christian Louboutin Shoes right now.
 

Sunday, September 13

转:有些东西就该丢掉,可偏就有人把那当作宝

作者 李笑来 Sept 11, 2009

我想将来我还会不停地遇到给我讲阴阳、五行、八卦、太极、中医、风水、佛教、基督教……诸如此类的“神秘而又灵验,并且往往难以驳斥”的各种理论——并且出于善意。

这其实多少有点像一台配置了酷睿双核CPU的电脑被主人固执地坚持使用DOS操作系统一样:

倒也不是说DOS就不是操作系统了,也不是说DOS就一无是处了,只是说,我们现在已经有更好的操作系统,比如Windows,或者Linux以及它的无数种发行版……

然而,如果坚持使用DOS的人声称“我乐意,你管得着么?!”,这就比较难办,因为我们又必须尊重个人选择。


不过,当我们尊重他们的“个人选择”之时,他们却不尊重给予他们尊重的人,不惜恶毒地“诅咒”(却又以“好意”的方式表达),这就多少有点令人难为情了。

有鉴于此,各自爱用啥用啥,好不好呢?

Saturday, August 8

[Music] The street where wind settles



When you are tired, you should listen to this melody.

If you are headed to a big party or other special occasion, these Christian Louboutin Ice sandals definitely fit the bill. Wear these Christian Louboutin with a black outfit for big time drama. The Louboutin feature cut-outs around the peep-toe, a buckle closure on the slingback and a 3-inch wrapped heel. You can order these Christian Louboutin Shoes right now.
 

Tuesday, July 21

疫苗与自闭症

中文论坛里关于疫苗引起自闭症的说法甚嚣尘上,所以我就做了一下research。

媒体上关于疫苗和自闭症关系的报道很多,有支持,也有反对。可是我的研究结果表明:到目前为止,支持疫苗引起自闭症的科学论文只有一篇半,而反对的汗牛充栋。

支持的第一篇论文于1998年发表在权威医学期刊《柳叶刀》上,作者为Andrew Wakefield为首的13个人。2004年,其中10个人在《柳叶刀》发表声明,退出这篇文章的签名。 (自然杂志 柳叶刀)
原因主要是:所研究的自闭症患儿中,一部分正由法律帮助委员会代理诉讼,而这个法律帮助委员会赞助了本项研究。发表前部分作者和柳叶刀杂志都不知道这一关联。

这篇论文是整个争论的正方的理论基础,可是却不太牢固的样子。一直没有别的科学/医学研究支持它的结论,直到2006年这半篇论文的出现:
之所以说是半篇,因为发表者不承认它的发表。2006年5月,许多媒体都报道Arthur Krigsman将在6月参加国际自闭症研究大会,发表疫苗引起自闭症的论文。(TimesOnline: US study supports claims of MMR link to autism 小儿麻疹风疹腮腺炎三联疫苗与自闭症有关联)。可是后来文章只是贴在会议墙上,作者没有与会,也否认这个研究已经发表。在联邦法庭上,作者宣称研究还没有完成。
Dr. Hepner and Dr. Krigsman testified that the study, which
began in 2003, is not yet complete, but that the group conducted some initial testing and presented “preliminary data” from the study at an autism-related conference in 2006, in the form of a “poster presentation” (literally, a poster board describing the study was set on an easel at the conference).(Federal Court Document, 2009)

然而,反对疫苗与自闭症有关联的研究真是汗牛充栋。让我偷懒一下,把中文维基上关于这个的争论都摘过来:
# 疫苗說

* 此學說首次提出,是在1988年2月出刊的刺針雜誌刊出由Andrew Wakefield為首的研究[3],表示自閉症可能和麻腮風三聯疫苗有關。但此研究有人批評可信性成疑。因為Andrew Wakefield有利益衝突。[4]二零零五年十月,考科藍協作網總結了31項有關自閉症和麻腮風三聯疫苗的研究,未有證據證明麻腮風三聯疫苗與自閉症有關。[5]
* 1998年由Gillberg領導的研究,分析瑞典由1975至1984年的數據,發現加入麻腮風三聯疫苗於防疫計劃之前和之後,自閉症的發病率沒有統計學上的明顯分別。[6]Madsen等於2002年發表的研究,分析丹麥由1991年至1998年的數據,也發現有接種麻腮風三聯疫苗與沒有接種麻腮風三聯疫苗之兒童的自閉證病發率沒有統計學上的明顯分別。[7]
* Kennedy首次發表Thimerosal(一種含有有機水銀的疫苗防腐劑)可能和自閉症有關。[8]他分析了水銀中毒和自閉症的病徵相似之處,也表示安曼教派兒童沒有接受防疫注射,自閉症發病率很低。此研究沒有任何流行病學數據支持。可是,美國疾病管制中心回應此研究,指Thimerosal不似是自閉症的原因。但基於公眾憂慮,疾病管制中心、食物及藥物管理局,及國家健康署共同於一九九九年發表聲明,要求藥廠停止使用Thimerosal作為疫苗防腐之用。
* Geier等發表了十一份研究,指出自閉症和兒童接種疫苗有關。他根據美國Vaccine Adverse Event Reporting System (VAERS)數據進行分析,指出美國防疫計劃使用沒有含有Thimerosal的疫苗後,美國兒童的自閉症發病率有所下降。美國兒科協會嚴重指摘此研究,表示VAERS的數據有偏頗,不能用於流行病學研究。Madsen的研究也發現,就算丹麥於1992年停用Thimerosal,自閉症的發病率也不跌反昇。

英文维基只是简单的说这个关联“生物上不可信,没有能说服力的科学证明(are biologically implausible and lack convincing scientific evidence)”,然后给出一堆引用文献:
Vaccines and autism:

与此同时,多家机构都不停宣布疫苗与自闭症无关:

2008-04-03 美國疾病管制中心、聯邦藥物管理局,以及世界衛生組織等,今天則是聯名發表聲明,指出MMR 疫苗的接種與自閉症發病之間並沒有任何關聯。 (中央社
2009年4月2日 众多国家的知名实验室均表示,现在有越来越多的充足证据可以压倒性地证明儿童接种疫苗不会增加自闭症患病危险(联合国电台
2008年9月24日 “这项研究确实终结了麻疹、腮腺炎和风疹疫苗与自闭症有关的猜测。”(美国之音

如果这些声音还不能消除民众的忧虑,到底怎样才可以?

关于疫苗与自闭症的流言,不仅浪费怠误了治疗自闭症患儿的时间、精力,而且造成越来越多的人拒绝疫苗。2008年美国麻疹爆发,就是一例。

Wednesday, July 15

Strategy和人相处的策略:当你被不公正对待的时候

你不想喝水,可是老板强迫你:“把这杯水喝下去!”

-你把水喝下去。
屈服。
-把这杯水泼到老板脸上。
攻击。

除此之外,你还能想到什么方式?
=======
=======
=======
-问老板:你为什么要我喝水?
商量协商解决方案。
-假装喝或不喝,让他永远猜不到我到底如何做。
拖延。
-请他喝水。
奉承。

还有其他办法!跳出框框来!
=======
=======
=======
-联合其他同事,一起反对喝水。
你不是一个人在战斗!联合其他人,你能够比权威更有力量!
-投诉
你不是第一个,也不是最后一个被这个老板不公正对待的。投诉的资料汇总起来,即使没有确凿的人证物证,投诉机关就可以明确谁是谁非了。

用自己的方式处世

西方圣经说:以牙还牙,以眼还眼。中国孔子说:子所不欲,勿施于人。两种说法有什么区别吗?

有。孔子的训诫是用自己的方式来对待别人,而西方的教导是用对方的方式来对待别人。

区别就是:你是否能够坚持自己,不因别人的做法而改变自己的态度。

有句话说:不要让自己讨厌的人把自己变成相同的人。这句话有点绕,不过如果别人要了你一口,你很生气这种行为,所以也去咬别人。这不就证明,因为这个你所讨厌的人,你也做了同样的事情?

要坚持自己的操守,并不是容易的事情。现在的世界,有太多的诱惑和借口,很容易让人迷失自我。

If you are headed to a big party or other special occasion, these Christian Louboutin Ice sandals definitely fit the bill. Wear these Christian Louboutin with a black outfit for big time drama. The Louboutin feature cut-outs around the peep-toe, a buckle closure on the slingback and a 3-inch wrapped heel. You can order these Christian Louboutin Shoes right now.
 

Tuesday, July 7

PhorumUpload Updated: Manage your uploaded files.

The previous version of PhorumUpload enables Phorum users to upload files, with a prompt:
Please be noticed that the file you are uploading will be available in Internet and might be circulating forever.

Using this program, users can manage (delete) their own uploaded files from server.

Download


// Copyright: This work is licensed under a Creative Commons License: Attribution-Noncommercial 2.0 Generic,
// the same as posts in my blog http://benincampus.blogspot.com
// You can retrieve the copyright detail from http://creativecommons.org/licenses/by-nc/2.0/
// This work was first deployed in http://www.oldbuddiesbbs.net/

// Ben@fadshop.net. July 06, 2009
// version 1.0:
// version 1.1: sort file output. disable ".." in the input string.



// Copyright: This work is licensed under a Creative Commons License: Attribution-Noncommercial 2.0 Generic,
// the same as posts in my blog http://benincampus.blogspot.com
// You can retrieve the copyright detail from http://creativecommons.org/licenses/by-nc/2.0/
// This work was first deployed in http://www.oldbuddiesbbs.net/

// Ben@fadshop.net. July 06, 2009
// version 1.0:
// version 1.1: sort file output. disable ".." in the input string.