custom validator working when i post it in the same page, however if i post to a different page it does not fire.

Jun 27 2012 6:22 AM
Question 1:
I am using a custom validator and when i post it in the same page it works and fires, however if i post to a different page it does not fire. Here is the code below.

Question2:
Also what is the best place to write the code for redirecting to the next page? in the action="pagename.aspx" or in the postbackurl="" of the button

<body class="nondnnbody14">
  <form id="form1" runat="server">
 
 <asp:PlaceHolder ID="PlaceHolder1" runat="server" EnableViewState="true"></asp:PlaceHolder>

  <td colspan="2" style="text-align: center">
  <asp:Label ID="lbl_message" runat="server" Text=""></asp:Label>
  <asp:Label ID="Label9" runat="server" Text=""></asp:Label>
  <br />
  <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please select price below." ControlToValidate="amount"></asp:RequiredFieldValidator>
  <br />
  <asp:CustomValidator ID="CustomValidator1" runat="server" OnServerValidate="Custom_Validator_Prepayment" ErrorMessage="Please select the type."></asp:CustomValidator>
  <br />
  </td>
  <td>
  <asp:Button id="button1" runat="server" text="Sign Up & Pay Now" PostBackUrl="~/Salsa_Classes/results.aspx" CausesValidation="true" onclick="button1_Click" />
  </td>





Code Behind

  protected void Custom_Validator_Prepayment(object s, ServerValidateEventArgs args)
  {

  if ((Session["id"] == null) || (Type.SelectedIndex == 0))
  {
  args.IsValid = false;
  Response.Redirect("default.aspx");
  }
  else
  {
  args.IsValid = true;
  }
  }

  protected void  button1_Click(object sender, EventArgs e)
  {

  //Page.Validate();
  if (!Page.IsValid)
  {
  Response.Redirect("../settings/studentmanager/default.aspx");
  }

}