mbosico
asked on
cross page posting and validation problems
I have a page that uses a customvalidator, so it does some server-side validation and I also put a PostBackUrl on the submit buttom. problem occurs that when i click the buttom, regardless if the validation failed or succeeded, it posts to the page. now i've read that i can just do PreviousPage.IsValid in the form_load event of the posted page to see if its valid, but how do I return to the previous page with the information intact...
///// REGISTER.ASPX //////
<asp:RequiredFieldValidato r ID="formShieldRequiredVd" runat="server" ControlToValidate="formShi eldTx"
ErrorMessage="Anti-Hacker Text Required" ForeColor="InactiveCaption ">*</asp:R equiredFie ldValidato r> <a sp:CustomV alidator
ID="formShieldDontMatchVd" runat="server"
ControlToValidate="formShi eldTx" ErrorMessage="Anti-Hacker text does not match"
ForeColor="InactiveCaption " OnServerValidate="formShie ldDontMatc hVd_Server Validate" Enabled="true">*</asp:Cust omValidato r>
<asp:Button ID="okBt" runat="server" Text="Register" PostBackUrl="~/emailInUse. aspx" />
protected void formShieldDontMatchVd_Serv erValidate (object source, ServerValidateEventArgs args)
{
try
{
args.IsValid = (formShieldTx.Text.Compare To(
this.formShield.Text) == 0);
}
catch (Exception)
{
args.IsValid = false;
}
}
////// emailInUse.aspx //////
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null && !PreviousPage.IsValid)
{
// need to redirect back to the previous page with data intact somehow and have the validation error displayed
}
}
///// REGISTER.ASPX //////
<asp:RequiredFieldValidato
ErrorMessage="Anti-Hacker Text Required" ForeColor="InactiveCaption
ID="formShieldDontMatchVd"
ControlToValidate="formShi
ForeColor="InactiveCaption
<asp:Button ID="okBt" runat="server" Text="Register" PostBackUrl="~/emailInUse.
protected void formShieldDontMatchVd_Serv
{
try
{
args.IsValid = (formShieldTx.Text.Compare
this.formShield.Text) == 0);
}
catch (Exception)
{
args.IsValid = false;
}
}
////// emailInUse.aspx //////
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null && !PreviousPage.IsValid)
{
// need to redirect back to the previous page with data intact somehow and have the validation error displayed
}
}
Can you validate on the current page, and then if validation succeeds, then do a Response.Redirect() or a Server.Transfer() to your new page, instead of validating on a different page?
ASKER
gregg1ep00:
I'd like it to be validated on the client side, but I don't know how because its a custom validation, I dont know how to get to the controls fields to check against what they type in.
formShieldTx.Text.CompareT o(this.for mShield.Te xt) == 0)
I'd like it to be validated on the client side, but I don't know how because its a custom validation, I dont know how to get to the controls fields to check against what they type in.
formShieldTx.Text.CompareT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in Page_Load of the destination page:
if (PreviousPage != null && !PreviousPage.IsValid)
{
Session["TextBoxEmail"] = ((TextBox)PreviousPage.Fin
Response.Redirect("~/Regis
}
then in page_Load of Register.aspx:
if (Session["TextBoxEmail"] != null)
{
TextBoxEmail.Text = (string)Session["TextBoxEm
Session.Remove("TextBoxEma
Validate();
}