Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am created a run time code to validate...
but its showing wrong whether i gave correct code....
why?


C#
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        long i = 1;
        foreach (byte b in Guid.NewGuid().ToByteArray())
        {
            i *= ((int)b + 1);
        }
        TextBox1.Text = string.Format("{0:x}", i - DateTime.Now.Ticks);

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == TextBox2.Text)
        {
            Response.Write("Hai");
        }
        else
        {
            Response.Write("wrong");
        }
    }
}
Posted

1 solution

You need to check for IsPostBack in your Page_Load code:

C#
protected void Page_Load(object sender, EventArgs e)
{
   if(!this.IsPostBack)
   {
      long i = 1;
      foreach (byte b in Guid.NewGuid().ToByteArray())
      {
         i *= ((int)b + 1);
      }
      TextBox1.Text = string.Format("{0:x}", i - DateTime.Now.Ticks);
   }
}
 
Share this answer
 
Comments
Raghupathiraja 9-Nov-11 5:53am    
thank u i got it ya
Tejas Vaishnav 9-Nov-11 6:03am    
My 5+
RaviRanjanKr 9-Nov-11 15:39pm    
My 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900