| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 599 人关注过本帖
标题:关于验证码的问题
只看楼主 加入收藏
gsx
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-28
收藏
 问题点数:0 回复次数:7 
关于验证码的问题
在页面放一个Image 控件。并把他的ImageUrl="xxbbsmain.aspx"(即在同一个页面生成随机数)
当我点击Button1时候,生成验证码就不成问题,但整个xxbbsmain.aspx页面的其它控件不见了 ,屏幕只显示刚才随机生成的数据而已。这是什么原因,请大家指点,指点一下吧,或有什么好的方法,告诉我,真的很急用啊
搜索更多相关主题的帖子: 验证 
2006-05-17 13:14
gsx
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-28
收藏
得分:0 

全部内容如下 刚才弄错了
关于验证码的问题?如下:private string GenCode(int num) { string[] source={"0","1","2","3","4","5","6","7","8","9", "A","B","C","D","E","F","G","H","I","J","K","L","M","N", "O","P","Q","R","S","T","U","V","W","X","Y","Z"}; string code=""; Random rd=new Random(); for(int i=0;i < num;i++) { code += source[rd.Next(0,source.Length)]; } return code; } private void GenImg(string code) { Bitmap myPalette = new Bitmap(85, 20);//定义一个画板
Graphics gh = Graphics.FromImage(myPalette);//在画板上定义绘图的实例

Rectangle rc = new Rectangle(0, 0, 85, 20);//定义一个矩形

gh.FillRectangle(new SolidBrush(Color.Blue), rc);//填充矩形
gh.DrawString(code, new Font("宋体", 16), new SolidBrush(Color.White), rc);//在矩形内画出字符串
myPalette.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);//将图片显示出来
Session["ValidateCode"] = code;//将字符串保存到Session中,以便需要时进行验证
gh.Dispose();
myPalette.Dispose();
}

protected void Button1_Click(object sender, EventArgs e)////////////////点击生成随机数
{
this.GenImg(this.GenCode(6));

}
在页面放一个Image 控件。并把他的ImageUrl="xxbbsmain.aspx"(即在同一个页面生成随机数)
当我点击Button1时候,生成验证码就不成问题,但整个xxbbsmain.aspx页面的其它控件不见了 ,屏幕只显示刚才随机生成的数据而已。这是什么原因,请大家指点,指点一下吧,或有什么好的方法,告诉我,真的很急用啊

2006-05-17 13:15
小笨笨
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:1169
专家分:0
注 册:2006-4-17
收藏
得分:0 

把其它的所有控件的EnableViewState都设成true
在Page_Load里加上

if (!this.IsPostBack)
{}


欢迎光临我的博客: http://smallfools.blog./default.html
2006-05-17 14:21
gsx
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-28
收藏
得分:0 
我页面的其他控件的EnableViewState都默认是true 但有的控件都没有EnableViewState属性的 那该怎么办 例如:table

2006-05-17 17:59
gsx
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-28
收藏
得分:0 

还是不行啊 笨笨姐 还是原来的样子啊

2006-05-17 18:09
小笨笨
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:1169
专家分:0
注 册:2006-4-17
收藏
得分:0 
把程序传上来,这样看不出来。

欢迎光临我的博客: http://smallfools.blog./default.html
2006-05-17 18:10
gsx
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-28
收藏
得分:0 

1.代码一:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;
using System.Web.SessionState;
using System.Drawing.Imaging;


public partial class xxbbsmain : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
this.LinkButton1.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
this.LinkButton1.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#777899'");
this.LinkButton2.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
this.LinkButton2.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#777899'");
this.LinkButton3.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
this.LinkButton3.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#777899'");
this.LinkButton4.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
this.LinkButton4.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#777899'");
this.LinkButton5.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
this.LinkButton5.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#777899'");
this.LinkButton6.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
this.LinkButton6.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#777899'");
this.LinkButton7.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
this.LinkButton7.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#777899'");
if (!IsPostBack)
{ }

}


protected void LinkButton1_Click(object sender, EventArgs e)
{

}
private string GenCode(int num)
{
string[] source={"0","1","2","3","4","5","6","7","8","9",
"A","B","C","D","E","F","G","H","I","J","K","L","M","N",
"O","P","Q","R","S","T","U","V","W","X","Y","Z"};
string code="";
Random rd=new Random();
for(int i=0;i < num;i++)
{
code += source[rd.Next(0,source.Length)];
}
return code;
}
private void GenImg(string code)
{
Bitmap myPalette = new Bitmap(85, 20);//定义一个画板

Graphics gh = Graphics.FromImage(myPalette);//在画板上定义绘图的实例

Rectangle rc = new Rectangle(0, 0, 85, 20);//定义一个矩形

gh.FillRectangle(new SolidBrush(Color.Blue), rc);//填充矩形
gh.DrawString(code, new Font("宋体", 16), new SolidBrush(Color.White), rc);//在矩形内画出字符串
myPalette.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);//将图片显示出来
Session["ValidateCode"] = code;//将字符串保存到Session中,以便需要时进行验证
gh.Dispose();
myPalette.Dispose();
}

protected void Button1_Click(object sender, EventArgs e)
{
this.GenImg(this.GenCode(6));

}
}
2.在html中就是:
<asp:Image ID="Image1" runat="server" Height="31px" ImageUrl="xxbbsmain.aspx" Style="z-index: 109;
left: 131px; position: absolute; top: 138px" Width="44px" />

2006-05-17 19:43
gsx
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-28
收藏
得分:0 

我弄好了 笨笨姐 其实把上面的代码 用一个页面生成 然后在它的页面放一个Image控件 然后把这Image控件拖放到xxbbsmain.aspx就可以了

2006-05-17 20:08
快速回复:关于验证码的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019751 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved