<!--
文章提供三種不同風格 asp教程.net 圖形驗證碼代碼。
<%@ page language="c#" contenttype="text/html" responseencoding="gb2312" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.111cn.net/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>三款asp.net教程 驗證碼代碼</title>
</head>
<body>
<%
<cc1:authcode id="authcode1" runat="server"
imagestyle-imgbgcolor="white" imagestyle-imgbordercolor="deeps教程kyblue" imagestyle-imgnoisecolor="ivory" imagestyle-textcolor1="azure"
imagestyle-textcolor2="ghostwhite" />
實現這種功能的關鍵在於 [designerserializationvisibility(designerserializationvisibility.content)]
以及 typeconverter(typeof(imagestyletypeconver)) 這兩個地方。
[designerserializationvisibility(designerserializationvisibility.content)] 提示屬性更改好產生
imagestyle-imgbgcolor="white" 這種代碼,至於 typeconverter(typeof(imagestyletypeconver))
則主要用於類型轉換,具體的見代碼裡的 imagestyletypeconver 類,該類是繼承於
expandableobjectconverter 類的,並且需要實現下面四個重載:
public override bool canconvertfrom(itypedescriptorcontext context, type sourcetype)
{
}
public override bool canconvertto(itypedescriptorcontext context, type destinationtype)
{
}
public override object convertfrom(itypedescriptorcontext context, cultureinfo culture, object value)
{
}
public override object convertto(itypedescriptorcontext context, cultureinfo culture, object value, type destinationtype)
{
}
方法二
asp.net中避免頁面多次提交的代碼:網頁特效< script language="javascript"> < !-- function disableothersubmit() {
var obj = event.srcelement;
var objs = document.getelementsbytagname('input');
for(var i=0; i< objs.length; i++)
{
if(objs[i].type.tolowercase() == 'submit')
{
objs[i].disabled = true;
}
}
} //--> < /script>//asp.net中避免頁面多次提交的代碼:asp.netpublic class preventmulticlick : system.web.ui.page {
protected system.web.ui.webcontrols.button button1; protected system.web.ui.webcontrols.button button2;
protected system.web.ui.webcontrols.linkbutton linkbutton1; protected system.web.ui.webcontrols.button button3; private void page_load(object sender, system.eventargs e)
{
this.getpostbackeventreference(this.button3);
//保證 __dopostback(eventtarget, eventargument) 精確註冊 if(!ispostback)
{
system.text.stringbuilder sb = new system.text.stringbuilder();
sb.append("if (typeof(page_clientvalidate) == 'function')
{
if (page_clientvalidate() == false)
{
return false;
}
}"); //保證考證函數的執行 sb.append("if(window.confirm('are you sure?')==false) return false; ");
//自訂用戶端指令碼 sb.append("disableothersubmit(); ");
// disable一切submit按鈕 sb.append(this.getpostbackeventreference(this.button3));
//用__dopostback來提交,保證按鈕的效勞器端click工作執行 sb.append("; ");
button3.attributes.add("onclick",sb.tostring());
}
} #region web form designer generated code override protected void oninit(eventargs e)
{
// // codegen: this call is required by the asp.net web form designer. // initializecomponent();
base.oninit(e);
}
/// < summary> /// required method for designer support - do not modify /// the contents of this method with the code editor. /// < /summary> private void initializecomponent()
{
this.button3.click += new system.eventhandler(this.button3_click); this.load += new system.eventhandler(this.page_load);
}
#endregion private void button3_click(object sender, system.eventargs e)
{
system.threading.thread.sleep(3000);
response.write("hello world!");
}
} 此處只是disable掉一切的submit button, 我感覺其它的可提交控制項也是能夠經由相似的辦法來disable的.