ASP Validation Group Not Working - asp.net

There are several pages which show the same code, just different field names.
What I'm struggling to understand is why the validation is not getting called on button click which is set to cause validation, all fields, required field validators and regular expression validators all have the same group.
Update
I remember this working (a project that got dropped and then picked up) previously, so the only things I can think of is either the web.config or the c# back end stopping it. I would not have thought the back end of the page is doing this as the button causes validation on click.
What else could be stopping this?
Code:
<%# Page Title="" Language="C#" MasterPageFile="~/DirectDebit/MasterDDSite.Master" AutoEventWireup="true" CodeBehind="DDI_2.aspx.cs" Inherits="CustomerServicePortal.DDI_Forms.DDI_2" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
function CheckNumeric(e) {
if (window.event) // IE
{
if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8) {
event.returnValue = false;
return false;
}
}
else { // Fire Fox
if ((e.which < 48 || e.which > 57) & e.which != 8) {
e.preventDefault();
return false;
}
}
}
</script>
<style type="text/css">
.style1 {
height: 28px;
}
table {
border-spacing: 2px;
border-collapse: separate;
}
.valError {
color: red;
border: 2px solid red;
margin: 5px 0px;
padding: 15px;
}
.valError ul {
color: red;
}
.valError li {
color: red;
}
.validation_summary {
color: red !important;
}
</style>
<div class="jumboservice">
<h2>Company Details</h2>
<div id="cmpnyDetails">
<div class="ui-grid-a">
<div class="ui-block-a">
<h4>Title:</h4>
</div>
<div class="ui-block-b">
<span>
<asp:TextBox ID="title" runat="server" ValidationGroup="vg1"></asp:TextBox>
*</span>
<asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="title" ValidationGroup="vg1" ErrorMessage="Title is a required field." Display="None"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator Display="None" ValidationGroup="vg1" ControlToValidate="title" ID="Rev3" ValidationExpression="^[\s\S]{2,5}$" runat="server" ErrorMessage="Title requires between 2 and 5 characters."></asp:RegularExpressionValidator>
</div>
</div>
<div class="ui-grid-a">
<div class="ui-block-a">
<h4>Forename(s):</h4>
</div>
<div class="ui-block-b">
<span>
<asp:TextBox ID="forename" runat="server" ValidationGroup="vg1"></asp:TextBox>
*</span>
<asp:RegularExpressionValidator Display="None" ValidationGroup="vg1" ControlToValidate="forename" ID="RegularExpressionValidator1" ValidationExpression="^[\s\S]{2,25}$" runat="server" ErrorMessage="Forename requires between 2 and 25 characters."></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="rfv2" runat="server" ControlToValidate="forename" ValidationGroup="vg1" ErrorMessage="Forename is a required field." Display="None"></asp:RequiredFieldValidator>
</div>
</div>
<div class="ui-grid-a">
<div class="ui-block-a">
<h4>Surname:</h4>
</div>
<div class="ui-block-b">
<span>
<asp:TextBox ID="surname" runat="server" ValidationGroup="vg1"></asp:TextBox>
*</span>
<asp:RequiredFieldValidator ID="rfv3" runat="server" ControlToValidate="surname" ValidationGroup="vg1" ErrorMessage="Surname is a required field." Display="None"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator Display="None" ValidationGroup="vg1" ControlToValidate="surname" ID="RegularExpressionValidator2" ValidationExpression="^[\s\S]{3,45}$" runat="server" ErrorMessage="Surname requires between 3 and 45 characters."></asp:RegularExpressionValidator>
</div>
</div>
<div class="ui-grid-a">
<div class="ui-block-a">
<h4>Telephone:</h4>
</div>
<div class="ui-block-b">
<span>
<asp:TextBox ID="CompanyTele" runat="server" onkeypress="CheckNumeric(event);" ValidationGroup="vg1"></asp:TextBox>
*</span>
<asp:RegularExpressionValidator Display="None" ValidationGroup="vg1" ControlToValidate="CompanyTele" ID="RegularExpressionValidator10" ValidationExpression="^[0-9]{10,20}$" runat="server" ErrorMessage="Telephone requires between 10 and 20 numbers."></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="rfv9" runat="server" ControlToValidate="CompanyTele" ValidationGroup="vg1" ErrorMessage="Telephone is a required field." Display="None"></asp:RequiredFieldValidator>
</div>
</div>
</div>
<p><strong>*</strong> - Fields marked with an asterisk are mandatory.</p>
<asp:ValidationSummary ID="ValidationSummary1"
runat="server" ShowMessageBox="false"
ShowSummary="true" ValidationGroup="vg1"
ForeColor="Red" DisplayMode="BulletList"
CssClass="valError" HeaderText="<span><strong>The below requires attention:</strong></span>" />
<div class="ui-grid-d">
<div class="ui-block-a">
<div data-role="main" class="ui-content">
<div data-role="controlgroup" data-type="horizontal">
<asp:Button ID="Submit" CausesValidation="true" ValidationGroup="vg1" runat="server" CssClass="ui-btn ui-corner-all" Text="continue" OnClick="Submit_Click" />
</div>
</div>
</div>
</div>
</div>
</asp:Content>

Remove the "validation group" from the text-box fields. You should only add the "validation group" in the validation field, referencing the control you wish to validate.

Related

How to wrap ASP.net validation controls in Bootstrap classes?

I am using Bootstrap 3 with ASP.NET webforms and I am completely new to Bootstrap. The webform I am working on uses ASP.net validation controls. My web form has a standard layout with two columns and I am using "form-group" class to group my labels and input fields.
Now the problem is that as I am placing the label, input field as well as its validator in the Bootstrap "form-group" class, the message in the text property of the validator is being displayed in the next line after validation. I want that to be displayed right next to the input field. Is there any alternative way I can do this?
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="txtBox">Address <span class="required">*</span></asp:Label>
<asp:TextBox id="txtBox" runat="server" CssClass="form-control"/>
<asp:RequiredFieldValidator ID="rfvLine1" ValidationGroup="<%# ValidationGroup %>" ControlToValidate="txtBox" runat="server" Display="Dynamic" ErrorMessage="Line 1 is required." Text="*"/>
</div>
Easiest way is to create validation in separate column.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
.required {
color: #e31937;
font-family: Verdana;
margin: 0 5px;
}
.field-validation-error {
color: #e31937;
font-weight: bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<br />
<div class="container form-horizontal">
<div class="form-group">
<asp:Label runat="server"
AssociatedControlID="txtBox"
CssClass="col-xs-12 col-sm-4 control-label">
Address
<span class="required">*</span>
</asp:Label>
<div class="col-xs-12 col-sm-4 ">
<asp:TextBox ID="txtBox" runat="server"
CssClass="form-control" />
</div>
<div class="col-xs-12 col-sm-4 form-control-static">
<asp:RequiredFieldValidator ID="rfvLine1"
ControlToValidate="txtBox" runat="server"
Display="Dynamic"
CssClass="field-validation-error"
Text="Line 1 is required." />
</div>
</div>
<div class="form-group">
<div class="col-xs-12 col-sm-offset-4 col-sm-4 ">
<asp:Button runat="server" ID="SubmitButton"
Text="Submit" CssClass="btn btn-primary" />
</div>
</div>
</div>
</form>
</body>
</html>
Do the following: Updated
<div class="container">
<h4 class="form-signin-heading">Info</h4>
<div class="form-group">
<div class="col-xs-7 col-sm-7">
<asp:TextBox runat="server" placeholder="Garage Name" CssClass="form-control username" ID="txtAddress"></asp:TextBox>
</div>
<div class="col-xs-7 col-sm-5">
<span class="help-inline pull-left">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtAddress"
ErrorMessage="Address is a required field."
ForeColor="Red" Display="Dynamic">
</asp:RequiredFieldValidator>
</span>
</div>
</div>
<br />
<br />
<div class="form-group">
<div class="col-xs-7 col-sm-7">
<asp:Button ID="Button1" runat="server" Text="Add" CssClass="btn btn-lg btn-primary btn-block" />
</div>
</div>
</div>
I hope, this is what you expected:
By the way, you didn't put the end tag in the RequiredFieldValidator.
#jQuery for check "require" validation for only submit button#
<script type="text/javascript">
(function () {'use strict';
window.addEventListener('load', function () {
var form = document.getElementById('needs-validation');
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false)
{
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
}, false);
})();
##Submit button HTML##
<asp:Button ID="Button1" runat="server" Text="Submit" class="btn btn-primary" OnClick="Button1_Click" />
##Non Submit button##
<asp:Button ID="btnSearch" runat="server" class="form-control btn-primary " Width="25%" Text="Find" UseSubmitBehavior="false" OnClick="btnSearch_Click" />

Changing controls order in row class div bootstrap 3

Well, I'am building a web application that uses twitter bootstrap 3 , and supports both languages English and Arabic with two different master pages for each,
am using div with class .row to put my controls inside
controls inside rows by default starts from left to right
when I change my website language to Arabic I want to reverse all items inside rows from right to left
am changing the master page with my stylesheet files, I've tried floating and directions but it never works for me for items inside div with .row class
<asp:Panel ID="pnl_TaskContent" runat="server" class="row">
<asp:Panel ID="pnl_TaskColumn" runat="server" class="col-md-12">
<div class="box-body">
<div class="row">
<div class="col-md-3">
<%--Task Name--%>
<div class="form-group">
<asp:Label ID="lbl_Task_Name" runat="server" Text="Task Name" Font-Bold="True" Font-Italic="False"></asp:Label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-pencil">
<asp:RequiredFieldValidator ID="RequiredFieldValidator27" runat="server" ErrorMessage="*"
ControlToValidate="txt_Task_Name" ForeColor="Red" ValidationGroup="saveTask" Font-Bold="True" Font-Size="Medium"></asp:RequiredFieldValidator>
</i></span>
<asp:TextBox ID="txt_Task_Name" runat="server" ClientIDMode="Static" CssClass="form-control"></asp:TextBox>
<div class="input-group-btn">
<asp:Button ID="button_tf" CssClass="btn btn-default dropdown-toggle" runat="server" Text="Functions" data-toggle="dropdown" ValidationGroup="none" />
<ul class="dropdown-menu">
<li>
<asp:Button ID="btn_AddTaskFunModal" CssClass="btn btn-default btn-block" runat="server" ValidationGroup="novali" Text="Add/Edit" data-toggle="modal" data-target="#addTaskFunctions-modal" /></li>
<li>
<asp:Button ID="btn_BrowseTaskFunModal" CssClass="btn btn-default btn-block" runat="server" ValidationGroup="novali" Text="Edit" data-toggle="modal" data-target="#BrowseTaskFunctions-modal" /></li>
</ul>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<%--Task Status--%>
<div class="form-group">
<asp:Label ID="lbl_Task_Status" runat="server" Text="Task Status" Font-Bold="True" Font-Italic="False"></asp:Label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-signal">
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ErrorMessage="*"
ControlToValidate="ddl_Task_Status" ForeColor="Red" ValidationGroup="saveTask" Font-Bold="True" Font-Size="Medium"></asp:RequiredFieldValidator>
</i></span>
<asp:DropDownList ID="ddl_Task_Status" runat="server" ClientIDMode="Static" CssClass="form-control" Enabled="False">
<asp:ListItem Value="N">New</asp:ListItem>
<asp:ListItem Value="A">Active</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</div>
<div class="col-md-3">
<%--Task Priority--%>
<div class="form-group">
<asp:Label ID="lbl_Task_Proirity" runat="server" Text="Task Priority" Font-Bold="True" Font-Italic="False"></asp:Label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-flag">
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ErrorMessage="*"
ControlToValidate="ddl_Task_Proirity" ForeColor="Red" ValidationGroup="saveTask" Font-Bold="True" Font-Size="Medium"></asp:RequiredFieldValidator>
</i></span>
<asp:DropDownList ID="ddl_Task_Proirity" runat="server" ClientIDMode="Static" CssClass="form-control">
<asp:ListItem Value="H">High</asp:ListItem>
<asp:ListItem Value="M">Medium</asp:ListItem>
<asp:ListItem Value="L">Low</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</div>
<div class="col-md-3">
<%--Completion Rate--%>
<div class="form-group">
<asp:Label ID="lbl_Task_CompRate" runat="server" Text="Completion Rate" Font-Bold="True" Font-Italic="False"></asp:Label>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txt_Task_CompRate" ErrorMessage="0-100" Font-Bold="True" ForeColor="Red" MaximumValue="100" MinimumValue="0" SetFocusOnError="True" Type="Integer" ValidationGroup="saveTask"></asp:RangeValidator>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-flag">
<asp:RequiredFieldValidator ID="RequiredFieldValidator31" runat="server" ErrorMessage="*"
ControlToValidate="txt_Task_CompRate" ForeColor="Red" Font-Bold="True" Font-Size="Medium" ValidationGroup="saveTask"></asp:RequiredFieldValidator>
</i></span>
<asp:TextBox ID="txt_Task_CompRate" runat="server" ClientIDMode="Static" CssClass="form-control">0</asp:TextBox>
<span class="input-group-addon"><i><b>%</b>
</i></span>
</div>
</div>
</div>
</div>
what i want that when i change the display order to rtl, is to change the controls inside my row
When Direction From Left To Right but controls are not showing as expected
Well, you have unusable html in your post, so I can't test this, but last year I contributed to this old repository: https://github.com/carasmo/bootstrap-rtl/blob/master/dist/css/bootstrap-rtl.css
Has some useful code when you change direction. It's 3.1 but some of it still works well. You'll have to pick through it to see what you need to tweek.
Here's an example of the input-group fixes:
DEMO: http://jsbin.com/tipufu/1/edit
Assumes
body {direction:rtl}
CSS for RTL:
.input-group .form-control:first-child,
.input-group-addon:first-child,
.input-group-btn:first-child > .btn,
.input-group-btn:first-child > .dropdown-toggle,
.input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle) {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-left-radius: 0;
border-top-left-radius: 0;
}
.input-group-addon:first-child {
border-right: 1px solid #cccccc;
border-left: 0;
}
.input-group .form-control:last-child,
.input-group-addon:last-child,
.input-group-btn:last-child > .btn,
.input-group-btn:last-child > .dropdown-toggle,
.input-group-btn:first-child > .btn:not(:first-child) {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-bottom-left-radius: 4px;
border-top-left-radius: 4px;
}
.input-group-addon:last-child {
border-right: 0;
border-left: 1px solid #cccccc;
}
.input-group-btn:first-child > .btn {
margin-left: -1px;
}
.input-group-btn:last-child > .btn {
margin-right: -1px;
}
.input-group-btn > .btn {
position: relative;
}
.input-group-btn > .btn + .btn {
margin-right: -4px;
}
.input-group-btn > .btn:hover,
.input-group-btn > .btn:active {
z-index: 2;
}
SOME HTML
<div class="input-group">
<span class="input-group-addon">#</span>
<input type="text" class="form-control" placeholder="Username">
</div>
<div class="input-group">
<input type="text" class="form-control">
<span class="input-group-addon">.00</span>
</div>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="text" class="form-control">
<span class="input-group-addon">.00</span>
</div>

click event in modal popup does not get fired

i have inquiry form which gets open in modal popup extender. when i click on button to store data click event does not get fired
i don't know whats going wrong can any one help me to solve this problem
thanks in advance
here is my code
DefaultMaster.master
<%# Master Language="C#" AutoEventWireup="true" CodeFile="DefaultMasterPage.master.cs"
Inherits="DefaultMasterPage" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link type="text/css" rel="Stylesheet" href="../JyotiInstitute/Styles/StyleSheet.css" />
<link type="text/css" rel="Stylesheet" href="../JyotiInstitute/Styles/sliderman.css" />
<link type="text/css" rel="Stylesheet" href="../JyotiInstitute/Styles/style1.css" />
<link type="text/css" rel="Stylesheet" href="../JyotiInstitute/Styles/style2.css" />
<script type="text/javascript" src="Script/jquery-1.3.2.js"></script>
<script type="text/javascript" src="Script/scroll-startstop.events.jquery.js"></script>
<script type="text/javascript" src="Script/sliderman.1.3.7.js"></script>
<script type="text/javascript" src="Script/easytabs.js"></script>
<script type="text/javascript" src="Script/modernizr.custom.04022.js"></script>
<script type="text/javascript" src="Script/modernizr.custom.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$('#toTop').fadeIn();
} else {
$('#toTop').fadeOut();
}
});
$('#toTop').click(function () {
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
});
$(function () {
$('.fadein img:gt(0)').hide();
setInterval(function () {
$('.fadein :first-child').fadeOut()
.next('img').fadeIn()
.end().appendTo('.fadein');
},
4000);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div class="page-wrap">
<div id="absolute">
<div id="div1" class="div1">
<asp:ImageButton runat="server" ImageUrl="Images/sef111.png" Style="margin-top: 10px;
margin-left: 5px" ID="OpenPopUp1" CausesValidation="false" OnClick="OpenPopUp1_Click" />
<asp:Button ID="btnPopUp1" runat="server" Style="display: none" />
</div>
<div id="div2" class="div2">
<asp:ImageButton ID="OpenPopUp2" runat="server" ImageUrl="Images/scef1.png" Style="margin-top: 2px;"
CausesValidation="false" OnClick="OpenPopUp2_Click" />
<asp:Button ID="btnPopUp2" runat="server" Style="display: none" />
</div>
</div>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground"
PopupControlID="Panel1" TargetControlID="btnPopUp1" CancelControlID="btnClose1">
</asp:ModalPopupExtender>
<asp:Panel runat="server" ID="Panel1" CssClass="modalPopup" align="center" Style="display: none">
<center>
<div class="outer_div">
<div class="inner_div">
<h1>
Student Enquiry Form</h1>
</div>
<div>
<br />
<asp:Literal runat="server" Text=" Your enquiry sent successfully..." ID="ltrMsg1"
Visible="false"></asp:Literal>
<br />
<asp:Label ID="Label2" runat="server" Text="Fileds marked with * are mandatory"></asp:Label>
<br />
<br />
<center>
<table>
<tr>
<td>
<asp:DropDownList ID="drpCourses" runat="server" CssClass="select">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtName" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender2" runat="server" TargetControlID="txtName" WatermarkText="* Full Name ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtEmail" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender3" runat="server" TargetControlID="txtEmail" WatermarkText="* E-mail ID ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" Text="+91" ReadOnly="true" CssClass="textbox"
Width="30px"></asp:TextBox>
<asp:TextBox runat="server" ID="txtMobile" CssClass="textbox" Width="172px"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender4" runat="server" TargetControlID="txtMobile" WatermarkText="* Mobile number ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtCity" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender6" runat="server" TargetControlID="txtCity" WatermarkText="City ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtState" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender5" runat="server" TargetControlID="txtState" WatermarkText="State ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtComments" TextMode="MultiLine" CssClass="textboxMulti"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender7" runat="server" TargetControlID="txtComments" WatermarkText="Comments ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<br />
<center>
<asp:Button ID="btnSave" Text="Save" runat="server" CssClass="btnConrol"
onclick="btnSave_Click" />
</center>
</td>
</tr>
</table>
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please select course"
SetFocusOnError="true" ControlToValidate="drpCourses" CssClass="ErrorMsg"></asp:RequiredFieldValidator><br />--%>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter full name"
SetFocusOnError="true" ControlToValidate="txtName" CssClass="ErrorMsg"></asp:RequiredFieldValidator><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please enter Email-ID"
SetFocusOnError="true" ControlToValidate="txtEmail" CssClass="ErrorMsg"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtEmail"
ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" runat="server"
CssClass="ErrorMsg" SetFocusOnError="true" ErrorMessage="Invalid Email" /><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Please enter mobile number"
SetFocusOnError="true" ControlToValidate="txtMobile" CssClass="ErrorMsg"></asp:RequiredFieldValidator>
</center>
</div>
</div>
</center>
<asp:ImageButton ImageUrl="Images/close1.png" runat="server" ID="btnClose1" Style="float: right;
margin-top: -645px; margin-right: -20px;" />
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtender_2" runat="server" BackgroundCssClass="modalBackground"
PopupControlID="Panel2" TargetControlID="btnPopUp2" CancelControlID="btnClose2">
</asp:ModalPopupExtender>
<asp:Panel runat="server" ID="Panel2" CssClass="modalPopup" align="center" Style="display: none">
<center>
<div class="outer_div">
<div class="inner_div">
<h1>
Institute Enquiry Form</h1>
</div>
<div>
<br />
<asp:Literal runat="server" Text=" Your enquiry sent successfully..." ID="ltrMsg2"
Visible="false"></asp:Literal>
<br />
<asp:Label ID="Label1" runat="server" Text="Fileds marked with * are mandatory"></asp:Label><br />
<br />
<table>
<tr>
<td>
<asp:TextBox runat="server" ID="txtFullName" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender8" runat="server" TargetControlID="txtFullName" WatermarkText="* Full Name ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtEmailId" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender9" runat="server" TargetControlID="txtEmailId" WatermarkText="* E-mail ID ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox3" runat="server" Text="+91" ReadOnly="true" CssClass="textbox"
Width="30px"></asp:TextBox>
<asp:TextBox runat="server" ID="txtMobileNum" CssClass="textbox" Width="172PX"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender10" runat="server" TargetControlID="txtMobileNum"
WatermarkText="* Mobile number ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtCityName" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender11" runat="server" TargetControlID="txtCityName"
WatermarkText="City ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtStateName" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender12" runat="server" TargetControlID="txtStateName"
WatermarkText="State ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtPin" CssClass="textbox"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender14" runat="server" TargetControlID="txtPin" WatermarkText="Pin Code ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" ID="txtComment" TextMode="MultiLine" CssClass="textboxMulti"></asp:TextBox><asp:TextBoxWatermarkExtender
ID="TextBoxWatermarkExtender13" runat="server" TargetControlID="txtComment" WatermarkText="Comments ">
</asp:TextBoxWatermarkExtender>
</td>
</tr>
<tr>
<td>
<br />
<center>
<asp:Button runat="server" ID="btnStore" Text="Save" CssClass="btnConrol"
onclick="btnStore_Click" />
</center>
</td>
</tr>
</table>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Field cannot be left blank"
SetFocusOnError="true" ControlToValidate="txtFullName" CssClass="ErrorMsg"></asp:RequiredFieldValidator><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="Field cannot be left blank"
SetFocusOnError="true" ControlToValidate="txtEmailId" CssClass="ErrorMsg"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regEmail" ControlToValidate="txtEmailId" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"
runat="server" CssClass="ErrorMsg" SetFocusOnError="true" ErrorMessage="Invalid Email" /><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Field cannot be left blank"
SetFocusOnError="true" ControlToValidate="txtMobileNum" CssClass="ErrorMsg"></asp:RequiredFieldValidator>
</div>
</div>
</center>
<asp:ImageButton ImageUrl="Images/close1.png" runat="server" ID="btnClose2" Style="float: right;
margin-top: -630px; margin-right: -20px;" />
</asp:Panel>
<div id="head-wrap">
<div id="back-wrap">
</div>
<div id="menu">
<ul class="tabs">
<li>News </li>
<li>E-Prospectus</li>
<li>Help Center</li>
<li>Contact Us</li>
<li>Test</li>
</ul>
</div>
<div id="tab-container">
<div id="tabs">
<div id="logo_hm">
<div id="hm_outer">
<a href="Index.aspx">
<img alt="" src="Images/hm.png" style="margin-left: 4px; margin-top: 4px; border-radius: 5px" /></a>
</div>
</div>
<div id="tab_outer">
<div id="MainMenu">
<center>
<ul id="nav">
<li style="display: inline"><span>Home</span></li>
<li style="display: inline; top: 0px; left: 0px;"><a href="AboutUs.aspx"><span>About
Us</span></a> </li>
<li style="display: inline"><span>Academics</span>
<ul class="nav first">
<li>Overview</li>
<li>Ordinances & Regulations</li>
<li>Programmes </li>
</ul>
</li>
<li style="display: inline; width: 100px"><span>Study Centers</span>
<ul class="nav first">
<li>Join As Study Center</li>
</ul>
</li>
<li style="display: inline"><span>Downloads</span></li>
</ul>
</center>
</div>
<div id="search-box">
<div id="searchwrapper">
<form action="">
<asp:TextBox runat="server" ID="txtSearch" CssClass="searchbox"></asp:TextBox>
<asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server" TargetControlID="txtSearch"
WatermarkText="Courses, Study Centers">
</asp:TextBoxWatermarkExtender>
<%-- <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="Images/search1.png"
CssClass="searchbox_submit" PostBackUrl="~/Search.aspx" />--%>
<a href="Search.aspx">
<img alt="" src="Images/search1.png" class="searchbox_submit" /></a>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="middle-wrap">
<div id="left">
<div id="logo">
<img alt="" src="Images/Jyoti_logo .jpg" width="100%" height="100%" />
</div>
</div>
<div id="right">
<div style="float: left;">
<div id="slider">
<div id="Div3" class="fadein">
<img src="Images/c1.jpg" alt="" />
<img src="Images/c2.jpg" alt="" />
<img src="Images/c3.jpg" alt="" />
<img src="Images/c4.jpg" alt="" />
<img src="Images/c5.jpg" alt="" />
</div>
<div class="SliderName_3Description">
<span>Jyoti Institute of IT & Management</span>
<br />
<span style="text-transform: none; font-size: 14px">Jaunpur (UP)</span>
</div>
<%-- <div class="slider">
<center>
<div id="slider_container_3">
<div id="SliderName_3">
<img alt="" src="Images/c1.jpg" />
<img alt="" src="Images/c2.jpg" />
<img alt="" src="Images/c3.jpg" /><img alt="" src="Images/c5.jpg" />
<img alt="" src="Images/c4.jpg" />
</div>
<div class="SliderName_3Description">
<span>Jyoti Institute of IT & Management</span>
<br />
<span style="text-transform: none; font-size: 14px">Jaunpur (UP)</span>
</div>
</div>
</center>
<script type="text/javascript">
demo3Effect1 = { name: 'myEffect31', top: true, move: true, duration: 400 };
demo3Effect2 = { name: 'myEffect32', right: true, move: true, duration: 400 };
demo3Effect3 = { name: 'myEffect33', bottom: true, move: true, duration: 400 };
demo3Effect4 = { name: 'myEffect34', left: true, move: true, duration: 400 };
demo3Effect5 = { name: 'myEffect35', rows: 3, cols: 9, delay: 50, duration: 100, order: 'random', fade: true };
demo3Effect6 = { name: 'myEffect36', rows: 2, cols: 4, delay: 100, duration: 400, order: 'random', fade: true, chess: true };
effectsDemo3 = [demo3Effect1, demo3Effect2, demo3Effect3, demo3Effect4, demo3Effect5, demo3Effect6, 'blinds'];
var demoSlider_3 = Sliderman.slider({ container: 'SliderName_3', width: 790, height: 300, effects: effectsDemo3,
display: { autoplay: 3000 },
description: { background: '#000000', opacity: 0.5, height: 30, position: 'bottom' }
});
</script>--%>
</div>
</div>
</div>
</div>
</div>
<div id="Content-wrap">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="site-footer">
<center>
<span>&COPY; Copyrights, 2013 Jyoti Institute | Designed & Developed by Weblord Infotech</span>
</center>
</div>
</form>
</body>
</html>
DefaultMaster.master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class DefaultMasterPage : System.Web.UI.MasterPage
{
Enquiry objEnquiry = new Enquiry();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void OpenPopUp1_Click(object sender, ImageClickEventArgs e)
{
ModalPopupExtender1.Show();
}
protected void OpenPopUp2_Click(object sender, ImageClickEventArgs e)
{
ModalPopupExtender_2.Show();
}
private void Clear()
{
drpCourses.SelectedIndex = 0;
txtName.Text = "";
txtFullName.Text = "";
txtEmail.Text = "";
txtEmailId.Text = "";
txtMobile.Text = "";
txtMobileNum.Text = "";
txtCity.Text = "";
txtCityName.Text = "";
txtState.Text = "";
txtStateName.Text = "";
txtPin.Text = "";
txtComment.Text = "";
txtComments.Text = "";
}
protected void btnStore_Click(object sender, EventArgs e)
{
//Studycenter enquiry form
//objEnquiry.EnterStudyCenterEnquiry(0, txtFullName.Text, txtEmailId.Text, txtMobileNum.Text, txtCityName.Text, txtStateName.Text, txtPin.Text, txtComment.Text);
ltrMsg2.Visible = true;
Clear();
}
protected void btnSave_Click(object sender, EventArgs e)
{
//Student enquiry form
//objEnquiry.EnterStudentEnquiry(0, drpCourses.SelectedItem.Text, txtName.Text, txtEmail.Text, txtMobile.Text, txtCity.Text, txtState.Text, txtComments.Text);
ltrMsg1.Visible = true;
Clear();
}
}
Is a request being submited to the server or is it not doing anything it all?
In the case of nothing happening my experience usually is a validationhandler that's invisible and blocking the call.
Try adding causesValidation="False" to your save button as a test to see if that is the issue
If it works without validation find the validator that's failing and fix it ! ;)
In my case I used UseSubmitBehavior="false". The reason behind this is explained here:
Microsoft Docs on UseSubmitBehavior
Gets or sets a value indicating whether the Button control uses the client browser's submit mechanism or the ASP.NET postback mechanism.
It appears that instead of trying to postback it was using the client browser submit so my code behind wasnt firing,

RequiredFieldValidator inside ModalPopup causing problems

I have an ASP.NET 3.5 form with several fields and a sub form inside a ModalPopup. The problem I'm having is with a RequiredFieldValidator inside the ModalPopup. For some reason it is preventing post back inside the ModalPopup. Both the validator and the submit buttons have the same ValidationGroup that is unique to them. Here is the markup for the sub form:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="RoomBuilder.ascx.cs" Inherits="Admin_Controls_RoomBuilder" %>
<link href="../../../../style/FlexStyle.css" rel="stylesheet" type="text/css" id="style"
runat="server" visible="false" />
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="form" style="width: 420px; height: 500px; padding: 3px; position: relative;
text-align: center;">
<div style="width: 280px">
<div class="item smalltitle ">
Title:
</div>
<div class="item">
<asp:TextBox ID="txtTitle" runat="server" Width="250px"></asp:TextBox>
</div>
<div class="item smalltitle gapontop">
Description:
</div>
<div class="item">
<asp:TextBox ID="txtDesc" runat="server" Width="250px" Height="40px" TextMode="MultiLine"></asp:TextBox>
</div>
<div class="item gapontop">
<div class="smalltitle floatLeft" style="width: 120px;">
Room Number
</div>
<div class="smalltitle floatLeft" style="width: 120px;">
Phone
</div>
</div>
<div class="item">
<div class="floatLeft" style="width: 120px;">
<asp:TextBox ID="txtRoomNo" runat="server" Width="100px"></asp:TextBox>
</div>
<div class="floatLeft" style="width: 120px;">
<asp:TextBox ID="txtPhone" runat="server" Width="100px"></asp:TextBox>
</div>
</div>
<div class="item smalltitle gapontop ">
Type:
</div>
<div class="item">
<asp:TextBox ID="txtType" runat="server" Width="250px"></asp:TextBox>
</div>
<div class="item smalltitle gapontop ">
Number of Seats:
<asp:RequiredFieldValidator ID="RequiredFieldValidatortxtNoSeats" runat="server" ErrorMessage="*"
ControlToValidate="txtNoSeats" ValidationGroup="roomVal"></asp:RequiredFieldValidator>
</div>
<div class="item">
<asp:TextBox ID="txtNoSeats" runat="server" Width="50px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Not a number"
ControlToValidate="txtNoSeats" ValidationGroup="roomVal" ValidationExpression="[0-9]*"></asp:RegularExpressionValidator>
</div>
</div>
<!-- ************************************ -->
<div class="topBorder" style="width: 100%; height: 35px; position: absolute; bottom: -8px;
right: 2px; text-align: right; padding-top: 11px;">
<asp:Button ID="btnCancel" runat="server" CssClass="button" Text="Cancel" CausesValidation="false"
OnClick="btnCancel_Click" ValidationGroup="roomVal" />
<asp:Button ID="btnSave" runat="server" CssClass="button" Text="Save" OnClick="btnSave_Click" CausesValidation="true" ValidationGroup="roomVal" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
When the validator is removed (or CausesValidation is set to false), the sub form posts. RegularExpressionValidators don't have this problem. I've run FireBug, but I'm not seeing any obvious errors.
Is there something I'm missing?
Oh my god I'm so stupid!! >:(
Found the reason for the problem. There was another copy of the same control nested inside another control. And (of course) having the same ValidationGroup name as my first control all Required Field Validators fail to work!
Argh! Candidate for a Daily WTF!
Sorry to have wasted everybody's time :(
Can you please check if your Button (or some other control) that open the popup and the modaldialog extender are outside the update panel?
I got strange problems with modalpopup too. I would suggest you to try something different, for example a numericupdown control from the ajaxcontroltoolkit, if you already use it. So you don't need any validator for this.
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<div class="item smalltitle gapontop ">
Number of Seats:
</div>
<div class="item">
<asp:TextBox ID="txtNoSeats" runat="server" Width="50px"></asp:TextBox>
<cc1:NumericUpDownExtender ID="txtNoSeatsExt" runat="server"
Enabled="true" Minimum="1" Maximum="100" TargetControlID="txtNoSeats" Width="50" />
</div>

asp.net validation controls - CSS placement

I am creating an address control which would use some address validation APIs( google/bing etc) to validate the user entered address. I would also like to validate the fields in the client side (like required fields, Zip format etc) with asp.net validation controls. I am trying to build this with CSS and am using float to align the text boxes (or is there a better way ?) The validation controls have dynamic display and want to place them next to the text boxes when they are not validated. Right now it wraps around/messes up with the placement of other controls. May be there is a better way of doing it ? Here is my code
<style type="text/css">
.Wrapper{
width:auto;
height:auto;
}
.address{
width:500px;
height:auto;
}
.validator{
}
.textbox {
float:right;
}
label{
float:left;
}
.button-right{
float:right;
margin-right:290px;
}
div{
margin:5px;
}
.field
{
width:200px;
}
</style>
<div id="addressUI" class="address">
<div class="field" >
<label ID="lblStreet" for="txtStreet">Street: </label><label style="color:Red">*</label>
<asp:TextBox ID="txtStreet" runat="server" CssClass="textbox" Text="" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rqdStreet" runat="server" ErrorMessage="Street is required" ControlToValidate="txtStreet" Display="Dynamic">
</asp:RequiredFieldValidator>
</div>
<div class="field">
<label ID="lblCity" for="txtCity">City: </label><label style="color:Red">*</label>
<asp:TextBox ID="txtCity" runat="server" Text="" CssClass="textbox" > </asp:TextBox>
<asp:RequiredFieldValidator ID="rqdCity" runat="server" ErrorMessage="City is required" ControlToValidate="txtCity" Display="Dynamic">
</asp:RequiredFieldValidator>
</div>
<div class="field">
<label ID="lblState" for="ddlState" >State: </label><label style="color:Red">*</label>
<asp:DropDownList ID="ddlState" runat="server" style="width:80px;margin-left:12px;" CssClass="">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rqdState" runat="server" ControlToValidate="ddlState" ErrorMessage="State is required" Display="Dynamic">
</asp:RequiredFieldValidator>
</div>
<div class="field">
<label ID="lblZip" for="txtZip">Zip: </label><label style="color:Red">*</label>
<asp:TextBox ID="txtZip" runat="server" CssClass="" Text="" style="width:50px;margin-left:22px;" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rqdZIP" ControlToValidate="txtZip" runat="server" ErrorMessage="ZIP is required" Display="Dynamic">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexValidator" runat="server"
ErrorMessage="Zip is invalid" Display="Dynamic" ControlToValidate="txtZip"
ValidationExpression="\d{5}(-\d{4})?"></asp:RegularExpressionValidator>
</div>
<div class="button-right">
<asp:Button ID="btnValidate" runat="server" Text="validate" OnClick="btnValidate_Click" CausesValidation="true" />
</div>
</div>
<head>
<style type="text/css">
label
{
display:inline;
float:left;
width:75px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="addressUI" class="address">
<div class="field">
<label id="lblStreet" for="txtStreet">
Street: <span style="color: Red">*</span>
</label>
<asp:TextBox ID="txtStreet" runat="server" CssClass="textbox" Text=""></asp:TextBox>
<asp:RequiredFieldValidator ID="rqdStreet" runat="server" ControlToValidate="txtStreet"
Display="Dynamic" ErrorMessage="Street is required">
</asp:RequiredFieldValidator>
</div>
<div class="field">
<label id="lblCity" for="txtCity">
City:<span style="color: Red">*</span>
</label>
<asp:TextBox ID="txtCity" runat="server" CssClass="textbox" Text=""> </asp:TextBox>
<asp:RequiredFieldValidator ID="rqdCity" runat="server" ControlToValidate="txtCity"
Display="Dynamic" ErrorMessage="City is required">
</asp:RequiredFieldValidator>
</div>
<div class="field">
<label id="lblState" for="ddlState">
State:<span style="color: Red">*</span>
</label>
<asp:DropDownList ID="ddlState" runat="server" CssClass="" Style="width: 80px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rqdState" runat="server" ControlToValidate="ddlState"
Display="Dynamic" ErrorMessage="State is required">
</asp:RequiredFieldValidator>
</div>
<div class="field">
<label id="lblZip" for="txtZip">
Zip:<span style="color: Red">*</span>
</label>
<asp:TextBox ID="txtZip" runat="server" CssClass="" Style="width: 50px"
Text=""></asp:TextBox>
<asp:RequiredFieldValidator ID="rqdZIP" runat="server" ControlToValidate="txtZip"
Display="Dynamic" ErrorMessage="ZIP is required">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regexValidator" runat="server" ControlToValidate="txtZip"
Display="static" ErrorMessage="Zip is invalid" ValidationExpression="\d{5}(-\d{4})?"></asp:RegularExpressionValidator>
</div>
<div class="button-right">
<asp:Button ID="btnValidate" runat="server" CausesValidation="true"
Text="validate" />
</div>
</div>
</div>
</form>
</body>
</html>

Resources