sbornstein2
asked on
Custom Validator Question
I have an ASPX page with a ASCX control on it. In the ASCX control I have validation going on and I just added a CustomValidator. On the ASPX page there is a save button that I have causesvalidation = true which works fine with the required fields etc. I dont want the user to move on unless they have saved a part of the ASCX control area. My code fires off on the ASPX button continue but it does not stop on that page and show the custom validator even when I am setting IsValid = false. Any ideas? Here is what I have:
ASCX Control:
<asp:CustomValidator id="CustomValidator1" runat="server" display="Dynamic" text="*" ErrorMessage="You must complete the Personal Information to continue" OnServerValidate="Validate _Save"/>
Code Behind:
protected void Validate_Save(object sender, ServerValidateEventArgs e)
{
if (Session["PersonalSaved"] != null)
{
if (Session["PersonalSaved"]. ToString() == "saved")
{
e.IsValid = true;
return;
}
else
{
e.IsValid = false;
return;
}
}
else
{
e.IsValid = false;
return;
}
}
Gets into that last e.IsValid = false then drops out and my next page loads from the Continue button on the ASPX page which I dont want. I need it to stay on this page and show the error. Thanks all
ASCX Control:
<asp:CustomValidator id="CustomValidator1" runat="server" display="Dynamic" text="*" ErrorMessage="You must complete the Personal Information to continue" OnServerValidate="Validate
Code Behind:
protected void Validate_Save(object sender, ServerValidateEventArgs e)
{
if (Session["PersonalSaved"] != null)
{
if (Session["PersonalSaved"].
{
e.IsValid = true;
return;
}
else
{
e.IsValid = false;
return;
}
}
else
{
e.IsValid = false;
return;
}
}
Gets into that last e.IsValid = false then drops out and my next page loads from the Continue button on the ASPX page which I dont want. I need it to stay on this page and show the error. Thanks all
What code do you have on the continue button?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Mores specifically, you need to issue a Page.Validate() or Page.Validate("groupname") before calling Page.IsValid..