I'm using two contact forms in the same aspx page, one has 4 textbox controls (name- email- subject- body) and send button control. The second form has 2 textbox controls and send button, all (except the second textbox of the second form) has validation controls (requiredFieldValidator).
This is the code inside the first button click event:
protected void ButtonSend_Click(object sender, EventArgs e)
{
if(Page.IsValid)
{
LabelIRespond.Visible = true;
.....
}
}
there is no code in the second button click event. the problem is, when the first form validated successful and the second form not validated, the code inside click event not executed. and the error message of the second form appears. They act like they are one form!
The markup for both forms:
<section id="sendSection">
<div id="contactMe">
<h1>Contact me</h1>
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h4>Send me a message:</h4>
<table class="auto-style1">
<tr>
<td class="auto-style8">
<asp:TextBox ID="TextBoxEmail" placeholder="Your Email address" runat="server" BackColor="#D4D8DF" Font-Names="Century Gothic" CssClass="txtbxs" Height="25px" Width="250px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorEmail" runat="server" ControlToValidate="TextBoxEmail" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Please enter your Email address">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBoxEmail" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RegularExpressionValidator" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style8">
<asp:TextBox ID="TextBoxName" placeholder="Your name" runat="server" BackColor="#D4D8DF" Font-Names="Century Gothic" CssClass="txtbxs" Height="25px" Width="250px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="TextBoxName" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5">
<asp:TextBox ID="TextBoxSubject" placeholder="Subject" runat="server" BackColor="#D4D8DF" Font-Names="Century Gothic" CssClass="txtbxs" Height="25px" Width="250px"></asp:TextBox>
</td>
<td class="auto-style3">
<asp:RequiredFieldValidator ID="RequiredFieldValidatorSubject" runat="server" ControlToValidate="TextBoxSubject" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style6">
<asp:TextBox ID="TextBoxBody" placeholder="What do you want to tell me?" runat="server" BackColor="#D4D8DF" TextMode="MultiLine" Font-Names="Century Gothic" CssClass="txtbxs" Height="180px" Width="370px"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:RequiredFieldValidator ID="RequiredFieldValidatorBody" runat="server" ControlToValidate="TextBoxBody" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Type your message">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style8">
<asp:Button ID="ButtonSend" runat="server" Text="Send" CssClass="btnSend" Width="80px" OnClick="ButtonSend_Click" UseSubmitBehavior="False" Font-Names="Century Gothic" />
</td>
<td>
</td>
</tr>
<tr>
<td class="auto-style8">
<asp:Label ID="LabelIRespond" runat="server" Text="Thanks, your message has been sent. I'll respond ASAP." Visible="False"></asp:Label>
</td>
<td>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="wait">
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</section>
<div class="split"></div>
<section id="viewCVSection">
<div id="check">
<h1>Check out my CV</h1>
</div>
<div class="cvForm">
<table class="auto-style1">
<tr>
<td class="auto-style4">
<asp:TextBox ID="TextBoxEmail2" placeholder="Company Email address" CssClass="txtbxs" runat="server" BackColor="#D4D8DF" Height="25px" Width="250px" Font-Names="Century Gothic"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxEmail2" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBoxEmail2" CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="RegularExpressionValidator" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style4">
<asp:TextBox ID="TextBoxCompany" placeholder="Company name" CssClass="txtbxs" runat="server" BackColor="#D4D8DF" Height="25px" Width="250px" Font-Names="Century Gothic"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style4">
<asp:Button ID="Button1" CssClass="sendCV" runat="server" Text="Request CV" Font-Names="Century Gothic" OnClick="Button1_Click" />
</td>
<td> </td>
</tr>
</table>
</div>
</section>
FirstGroupand then set the same property for second contact form button and validators toSecondGroup. It will work then. - SunilButtonSend1is in which contact form? - Sunil