title: popup alert message asp.net
body: <p>I'm working with a simple asp.net barcode application, I need to display a popup message when some validation is not the right one.</p>
  
  <p>The thing is that my message is working only after I push the "submit" button two times. The first time just the page is reload, and if I push the button again, the popup do appear!</p>
  
  <p>EDIT: I just forget to add some details. I'm using VS 2010, building a Web Application asp.net with C# as code behind.</p>
  
  <pre><code>public partial class Barcode : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (IsPostBack)
          {
              Validate();
  
              if (IsValid)
              // 
              {
                  string kemet = kemetTextBox.Text;
                  string sud = sudTextBox.Text;
  
                  if (kemet.Length == 14 &amp;&amp; sud.Length == 28) // SOME VALIDATION CONTROL
                  {
  
                      if (kemet.Substring(1) == sud.Substring(0, 13) &amp;&amp; kemet != "" &amp;&amp; sud != "")
                      {
  
                          //resultLabel.Text = "HIGH VOLUME&lt;br/&gt;";
                          redImage.Visible = false;
                          greenImage.Visible = true;
  
                      }
                      if (kemet.Substring(1) != sud.Substring(0, 13) &amp;&amp; kemet != null &amp;&amp; sud != null)
                      {
  
                          //  resultLabel.Text = "LOW VOLUME&lt;br/&gt;" + kemetEd + sudEd;
                          greenImage.Visible = false;
                          redImage.Visible = true;
                      }
                  }
                  else
                      Button1.Attributes.Add("onClick", "javascript:alert('Message Here');"); // HERE WOULD BE THE ERROR MSG 
  </code></pre>
  
  <p>I try to make the IsPostBack false, but that just made it worse.</p>
  
  <p>thank you!</p>