I am writing a captcha authentication program in ASP.NET C#. The problem i face is that the image gets refreshed on entering wrong value during a postback; but same image doesn't get refreshed during a partial postback, when i keep them inside an update panel.
aspx source
Code Behind:
private System.Random rand = new System.Random();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.Session["Captcha"] = GenerateRandomCode();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string temp = this.Session["Captcha"].ToString();
if (string.Compare(temp, this.txtCaptcha.Text.Trim()) == 0)
{
// success logic
}
else
{
this.lblResult.Text = "Validation Text was not correct.";
this.Session["Captcha"] = GenerateRandomCode();
ImageCaptcha.ImageUrl = "~/BringImg.aspx";
ImageCaptcha.DataBind();
}
}