Solved

cross page posting and validation problems

Posted on 2006-06-23
4
1,198 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DLL in ASP.NET 20 56
Achieve json result 2 65
Registering DLL 5 43
Host asp.net pages 5 25
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now