自定义控件与IHttpHandler
我在控件里设置为属性
internal static Color fontcolor;
public Color FontColor
{
set { ValidateImage.fontcolor = value; }
get { return ValidateImage.fontcolor; }
}
这个是一个组建,调用了IHttpHandler,
public void ProcessRequest(HttpContext context)
{
if (ValidateImage.width.ToString() != "")
{
Bitmap BitImg = new Bitmap(ValidateImage.width, ValidateImage.height);
Graphics GrapObj = Graphics.FromImage(BitImg);
if (ValidateImage.backimage != null)
{
Bitmap BitBack = new Bitmap(ValidateImage.backimage);
GrapObj.DrawImage(BitBack, 0, 0, ValidateImage.width, ValidateImage.height);
}
Random Rnd = new Random();
string StringValue = Rnd.Next(1000, 9999).ToString();
context.Session[ValidateImage.sessionname] = StringValue;
GrapObj.DrawString(StringValue, new Font("宋体", ValidateImage.fontsize, FontStyle.Bold), new SolidBrush(ValidateImage.fontcolor), ValidateImage.x, ValidateImage.y);
context.Response.ContentType = "image/Jpeg";
System.IO.MemoryStream Memory = new System.IO.MemoryStream();
BitImg.Save(Memory, System.Drawing.Imaging.ImageFormat.Bmp);
context.Response.BinaryWrite(Memory.ToArray());
}
}
public bool IsReusable
{
get { return true; }
}
这是接口实现的方法,但是我在aspx页面<uc1:ValidateImage ImgHeight="21" ImgWidth="50"
ValidateSessionName ="ValidateValue" CssClass="img1" runat="server" X="3" Y="2"
FontColor="#cccccc" FontSize="12" ID="ValidateControl" >
设置了,一些相关属性,但是在组建的ProcessRequest这个方法里,第一次根本没有值,我想问下怎么能解决这个问题