ImageButtom problem

  • Thread starter Thread starter Joe Bonavita
  • Start date Start date
J

Joe Bonavita

In the click event of the button I do some validation. If everything is
valid the code falls through to a Server.Transfer("nextpage.aspx");

The problem is if I leave in the Server.Transfer("nextpage.aspx"); it just
tries to go to the next page and doesn't do the validation. Why? It's almost
like memory becomes corrupt (like in C++).

the code looks like this:

private void ImageButton2_Click(object sender,
System.Web.UI.ImageClickEventArgs e)

{

if (TextBoxTo.Text.Length == 0)

DisplayMessage("The To: Email address is empty. Enter an email address and
try again.");


if (!IsEmailOfValidForm(TextBoxTo.Text) )

DisplayMessage("The To: Email address is not of a valid form.");

if (TextBoxFrom.Text.Length == 0)

DisplayMessage("The From: Email address is empty. Enter an email address and
try again.");


if (!IsEmailOfValidForm(TextBoxFrom.Text) )

DisplayMessage("The From: Email address is not of a valid form.");

if (TextBoxMessage.Text.Length == 0)

DisplayMessage("You must enter a message for your card. Enter a message and
try again.");


if (!CheckBoxYes.Checked)

DisplayMessage("You must check the 'Yes' box to confirm that everything is
ok.");


Server.Transfer ("checkout.aspx");

}
 
Try below code. Should work.

private void ImageButton2_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
boolean Error =false;
if (TextBoxTo.Text.Length == 0)
{
DisplayMessage("The To: Email address is empty. Enter an email address
and try again.");
Error=true;
}

if (!IsEmailOfValidForm(TextBoxTo.Text) )
{
DisplayMessage("The To: Email address is not of a valid form.");
Error=true;
}

if (TextBoxFrom.Text.Length == 0)
{
DisplayMessage("The From: Email address is empty. Enter an email address
and try again.");
Error=true;
}


if (!IsEmailOfValidForm(TextBoxFrom.Text) )
{
DisplayMessage("The From: Email address is not of a valid form.");
Error=true;
}

if (TextBoxMessage.Text.Length == 0)
{
DisplayMessage("You must enter a message for your card. Enter a message
andtry again.");
Error=true;
}


if (!CheckBoxYes.Checked)
{
DisplayMessage("You must check the 'Yes' box to confirm that everything
is ok.");
Error=true;
}
//New code Added
if (Error)
return;
Server.Transfer ("checkout.aspx");

}

Thanks,

sswalia
MCAD, MCSD, OCA
 
Back
Top