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.
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!
EDIT: I just forget to add some details. I’m using VS 2010, building a Web Application asp.net with C# as code behind.
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 && sud.Length == 28) // SOME VALIDATION CONTROL
{
if (kemet.Substring(1) == sud.Substring(0, 13) && kemet != "" && sud != "")
{
//resultLabel.Text = "HIGH VOLUME<br/>";
redImage.Visible = false;
greenImage.Visible = true;
}
if (kemet.Substring(1) != sud.Substring(0, 13) && kemet != null && sud != null)
{
// resultLabel.Text = "LOW VOLUME<br/>" + kemetEd + sudEd;
greenImage.Visible = false;
redImage.Visible = true;
}
}
else
Button1.Attributes.Add("onClick", "javascript:alert('Message Here');"); // HERE WOULD BE THE ERROR MSG
I try to make the IsPostBack false, but that just made it worse.
thank you!
Try replacing this:
By this:
Which uses the following helper methods:
This will make sure your message will only be displayed after the document is ready, preventing ugly formatting issues.