Hi, I have some fields to be validated on the server (CustomValidator) which is in a separate user control and my Submit button is in the page not in the user control.
What I have done is, I placed all my Validation Methods in the code behind of my usercontrol (ascx.cs) and the page validation is in the code behind of the page (aspx.cs). I put them in the same ValidationGroupName (fields and Submit button). usercontrol (ascx) is a child of my page (aspx). I have already placed CauseValidation="true"
to my Button and UseSubmitBehavior="true"
. The problem is it does not validate. What could be the problem in this?
Note: I cannot put the the Button to be part of the usercontrol.
Edit:
in my aspx page, click event of the button has this.Page.Validate(ValidationGroupName)
and all of my validators are on the fields on a separate control (ascx) which is a child of the aspx page.
protected void Button1_Command(object sender, CommandEventArgs e)
{
if(e.CommandName.Equals("Validate", StringComparison.Ordinal))
{
this.Page.Validate("MyValidationGroup");
if(this.Page.IsValid)
{
// I'll change my View here.
}
}
}
My Button looks like
<asp:Button ID="Button1" runat="server" UseSubmitBehavior="true" CommandName="Validate"
Text="Submit" OnCommand="Button1_Command" CausesValidation="true" ValidationGroup="MyValidationGroup" />
The above snippet is located in my aspx page.
I've tried to put the same button on the ascx page, it works fine. My thought is since the ascx page is under the aspx page. When the button event on aspx page is fired (Button1), the rest of the event in ascx page is not fired. I've tried to put breakpoints on the button event and validator events, if the button of the page (aspx) is the one I click, it will not stop on my validator events, if the button on the control (ascx) I click it will stop to the validator events. What could be the remedy for this?