当前位置:编程学习 > C#/ASP.NET >>

三款asp.net 验证码代码(1/2)

<!--
文章提供三种不同风格 asp教程.net 图形验证码代码。

<%@ page language="c#" contenttype="text/html" responseencoding="gb2312" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.zzzyk.com/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的.

1 2
补充:asp.net教程,.Net开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,