So this is what i have
protected void submitEmail_Click(object sender, EventArgs e)
{
try
{
if (!Page.IsValid)
{
validationMsg.Visible = true;
validationMsg.Text = "Please insert a valid email address.";
return;
}
if (!IsValidEmail())
{
validationMsg.Visible = true;
validationMsg.Text = "Please insert a valid email address.";
return;
}
SaveData();
validationMsg.Visible = true;
validationMsg.Text = "Thank you for joining our beta community! We’ll send word as soon as our beta is out.";
}
catch (Exception ex)
{
}
}
And a .aspx
:
<%@ Control Language="C#"
AutoEventWireup="true"
CodeFile="BetaEmailUserForm.ascx.cs"
Inherits="CMSWebParts_BullGuard_User_Forms_BetaEmailUserForm" %>
<div class="subscribe">
<asp:TextBox ID="userEmail" runat="server"
CssClass="subscribe-input"></asp:TextBox>
<asp:LinkButton ID="submitEmail" runat="server"
OnClick="submitEmail_Click"
CssClass="subscribe-submit button"
CausesValidation="true"
ValidationGroup="betaEmailGroup">
<span style="font-size: 20px; color: #ffffff;padding: 26px;display:block;">✓</span>
</asp:LinkButton>
</div>
<p class="thank">
<asp:Literal ID="validationMsg"
runat="server"
Visible="false"></asp:Literal>
<asp:RequiredFieldValidator ID="rfvEmail1new"
ControlToValidate="userEmail"
SetFocusOnError="true"
EnableClientScript="true"
ValidationGroup="betaEmailGroup"
runat="server"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmail1new"
ControlToValidate="userEmail"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
SetFocusOnError="true"
EnableClientScript="true"
ValidationGroup="betaEmailGroup"
runat="server"></asp:RegularExpressionValidator>
</p>
What i want is this.
case 1 : i enter nothing in the input filed the 1st validator takes action and in the .cs file i assume that the 1st condition should fail, resulting in adding the message
case 2 : i enter an invalid email address => same logic as for case 1
case 3 : enter a good email address skip the 2 checks
case 4 : enter an already registered email address ==> go to 2nd check condition.
The issue is that i don't get the messages displayed for the 2 Validators.
1st case I don't enter any data i want to go with the following case
if (!Page.IsValid)
It does not happen.
2nd case that fails is if the email address is not correct (eg. asdasd@dadad)
should also go with the case where page is not valid
if (!Page.IsValid)
I've tried to debug butcouldn't debug for the 1st and 2nd test cases. I can debug only if i enter a valid email address.
Any help? thank you.
I'm thinking that there are some client side validation that the aspx controllers will do for me in the back without my knowledge, some js generated files? don't know