By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,819 Members | 1,573 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,819 IT Pros & Developers. It's quick & easy.

Create a random code and store it in the Session object

P: 15
hii i hav a problem with thsi code
check it once
Expand|Select|Wrap|Line Numbers
  1. if (!this.IsPostBack)
  2.  
  3. // Create a random code and store it in the Session object.
  4.  
  5. this.Session["CaptchaImageText"] = GenerateRandomCode();
  6.  
  7. else
  8.  
  9. {
  10.  
  11. // On a postback, check the user input.
  12.  
  13. if (this.CodeNumberTextBox.Text ==
  14.  
  15. this.Session["CaptchaImageText"].ToString())
  16.  
  17. {
  18.  
  19. // Display an informational message.
  20.  
  21. this.MessageLabel.CssClass = "info";
  22.  
  23. this.MessageLabel.Text = "Correct!";
  24.  
  25. }
  26.  
  27. else
  28.  
  29. {
  30.  
  31. //Display an error message.
  32.  
  33. this.MessageLabel.CssClass = "error";
  34.  
  35. this.MessageLabel.Text = "ERROR: Incorrect, try again.";
  36.  
  37. // Clear the input and create a new random code.
  38.  
  39. this.CodeNumberTextBox.Text = "";
  40.  
  41. this.Session["CaptchaImageText"] = GenerateRandomCode();
  42.  
  43. }
  44.  
  45. }
  46.  
  47. }
the second else is directly executing without anywrong entry of text
so please tell how to correct thsi code
Aug 27 '08 #1
Share this Question
Share on Google+
2 Replies


kenobewan
Expert 2.5K+
P: 4,871
Suggest using try catch to debug errors...
Aug 27 '08 #2

Expert 100+
P: 427
Try inserting a break point on the second if statement to make sure that the values are what they should be, it would appear to me that one of those values gets an unexpected value and thus the 2 are never equal
Aug 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.