Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

cross page posting and validation problems

Posted on 2006-06-23
4
Medium Priority
?
1,218 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

927 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