Solved

cross page posting and validation problems

Posted on 2006-06-23
4
1,204 Views
Last Modified: 2008-02-01
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:RequiredFieldValidator ID="formShieldRequiredVd" runat="server" ControlToValidate="formShieldTx"
        ErrorMessage="Anti-Hacker Text Required" ForeColor="InactiveCaption">*</asp:RequiredFieldValidator>&nbsp;<asp:CustomValidator
            ID="formShieldDontMatchVd" runat="server"
            ControlToValidate="formShieldTx" ErrorMessage="Anti-Hacker text does not match"
            ForeColor="InactiveCaption" OnServerValidate="formShieldDontMatchVd_ServerValidate" Enabled="true">*</asp:CustomValidator>
<asp:Button ID="okBt" runat="server" Text="Register" PostBackUrl="~/emailInUse.aspx" />

protected void formShieldDontMatchVd_ServerValidate(object source, ServerValidateEventArgs args)
    {
        try
        {
            args.IsValid = (formShieldTx.Text.CompareTo(
                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
        }
      }
0
Comment
Question by:mbosico
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:e1v
ID: 16969327
This is what I did in a situation like yours, I only had one textbox (TextBoxEmail) on the previous page (Register.aspx) that had to be restored.

in Page_Load of the destination page:

if (PreviousPage != null && !PreviousPage.IsValid)
{
     Session["TextBoxEmail"] = ((TextBox)PreviousPage.FindControl("TextBoxEmail")).Text;
     Response.Redirect("~/Register.aspx", false);
}

then in page_Load of Register.aspx:
   if (Session["TextBoxEmail"] != null)
        {
            TextBoxEmail.Text = (string)Session["TextBoxEmail"];
            Session.Remove("TextBoxEmail");
            Validate();
        }

0
 
LVL 4

Expert Comment

by:gregg1ep00
ID: 16970174
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?
0
 

Author Comment

by:mbosico
ID: 16970687
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.CompareTo(this.formShield.Text) == 0)
0
 
LVL 4

Accepted Solution

by:
gregg1ep00 earned 250 total points
ID: 16971104
If you want it to be validated on the client side, change the CustomValidator to a CompareValidator, and in your code-behind (in Page_Load), set the CompareValidator's "ValueToCompare" property to the formshield's text property.

This will pose a security risk, however, since your formshield's text will be visible in plain text when you view the source of the rendered page (look in the javascript functions in that page).
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question