Hi I am developing a web page which will give the details of customer. I have several validations for input fields and used DetailsView for displaying details of customer. If the user details does not exist in database Detailsview displays a message "No records found". Now if I enters an invalid user name validations are displayed but page still have the "No records found" message in EmptyDataTemplate of DetailsView. How can I remove "No records found" message or disable details view ? So that page should only show error messages and textbox fields.
<asp:TextBox ID="TextBox_FirstName" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator_FirstName" runat="server"
ControlToValidate="TextBox_FirstName" ErrorMessage="Enter a valid SSN" ForeColor="Red"
SetFocusOnError="True">*</asp:RegularExpressionValidator>
<br />
<asp:TextBox ID="TextBox_LastName" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator_LastName" runat="server"
ControlToValidate="TextBox_LastName" ErrorMessage="Enter a valid date" ForeColor="Red">*</asp:RegularExpressionValidator>
<asp:Button ID="txtSubmit" Text="Validate" runat="server" />
<asp:CustomValidator ID="AtLeastOneTextBoxValidator" runat="server" ClientValidationFunction="Validate_Textbox"
ValidateEmptyText="true"> </asp:CustomValidator>
<asp:ValidationSummary ID="ValidationSummary" runat="server" />
<asp:DetailsView ID="Client_DetailsView" runat="server">
<EmptyDataTemplate>
<strong>No Record Found.</strong>
</EmptyDataTemplate>
</asp:DetailsView>
Change your code behind so that Client_DetailsView only gets data bound when they submit the form.
Also, set it's visibility to hidden in the .aspx then only set it to visible when the form is submitted.
Related
I have 2 textboxes called minimum version and maximum version requesting user to enter Version ( like 1.3.4 ). At a given time only one can be blank, not both So I have provided custom field validator .Also I have provided regular expression to validate if values entered are proper.
When I click on button entering invalid version field I can see button click event is getting triggered. Could you please help.
<asp:Label ID="lblMinimum" runat="server" Text="Minimum Version : " CssClass="alignLeft"></asp:Label>
<asp:TextBox ID="txtMinimumVersion" runat="server" Width="312px" CssClass="alignRight" ValidationGroup="validate"></asp:TextBox>
<asp:RegularExpressionValidator ID="revModuleVersion" runat="server" ControlToValidate="txtMinimumVersion"
ValidationExpression="^\d+(\.\d+)+$" ErrorMessage="* Please enter valid version number" ValidationGroup="validate"/>
<asp:Label ID="lblMaximum" runat="server" Text="Maximum Version : " CssClass="alignLeft"></asp:Label>
<asp:TextBox ID="txtMaximumVersion" runat="server" Width="312px" CssClass="alignRight" ValidationGroup="validate"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtMaximumVersion"
ValidationExpression="^\d+(\.\d+)+$" ErrorMessage="* Please enter valid version number" ValidationGroup="validate"/>
<asp:Button ID="btnUpdateNow" runat="server" EnableViewState="False" Text="Create now"
OnClick="btnCreateNow_Click" CausesValidation="false" ValidationGroup="validate"></asp:Button>
<asp:CustomValidator ID="custValidateModuleVersion" runat="server" Display="Dynamic" ErrorMessage="* Maximum version should be greather or equal to Minimum version"
OnServerValidate="custValidateModuleVersion_ServerValidate"></asp:CustomValidator>
<asp:CustomValidator ID="custValidate" runat="server" Display="Dynamic" ErrorMessage="* Please enter atleast one version"
OnServerValidate="CustomValidator_ServerValidate"></asp:CustomValidator>
You have mentioned CausesValidation = "false". Make it as true or remove it
<asp:Button ID="btnUpdateNow" runat="server" EnableViewState="False" Text="Create now" OnClick="btnCreateNow_Click" ValidationGroup="validate"></asp:Button>
The CausesValidation property specifies if a page is validated when a Button control is clicked.
Page validation is performed when a button is clicked by default.
This property is mostly used to prevent validation when a cancel or reset button is clicked.
I have search textbox,which has default value Enter Month to View Profit. When I click search button without entering any data, the default value of textbox is posted to server for search. I want that RegularExpressionValidator do not validate default value of textbox.
<asp:TextBox ID="Tboxsearch" Text="Enter Month to View Profit" OnClick="this.value=''" CssClass="textboxinput" runat="server"></asp:TextBox>
<asp:Button ID="ButtonSearch" CssClass="btnLog" runat="server" Text="Search" onclick="ButtonSearch_Click" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidatorname"
runat="server"
ControlToValidate="Tboxsearch"
ForeColor="Red"
Text="*"
>
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidatorname"
runat="server"
ValidationExpression="[a-zA-Z0-9]+"
ForeColor="Red"
ControlToValidate="Tboxsearch"
ErrorMessage="Enter Valid Name!"
>
</asp:RegularExpressionValidator>
The default for all validators except the RequiredFieldValidator control if you post with empty field the validator will not trigger
you must use required field validator with other validators to prevent the postback to happen
from MSDN
Special-Case Validation Results for ASP.NET Server Controls
EDIT
Also if you add your controls as in your question it should work but if there is other controls like for example other button you should set the validationGroup Property to the group that you want to work together
ValidationGroup="vGrp"
and your code will be like this
<asp:TextBox ID="Tboxsearch" Text="Enter Month to View Profit" OnClick="this.value=''" CssClass="textboxinput" runat="server" ValidationGroup="vGrp"></asp:TextBox>
<asp:Button ID="ButtonSearch" CssClass="btnLog" runat="server" Text="Search" onclick="ButtonSearch_Click" ValidationGroup="vGrp" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidatorname"
runat="server"
ControlToValidate="Tboxsearch"
ForeColor="Red"
Text="*"
ValidationGroup="vGrp">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidatorname"
runat="server"
ValidationExpression="[a-zA-Z0-9]+"
ForeColor="Red"
ControlToValidate="Tboxsearch"
ErrorMessage="Enter Valid Name!" ValidationGroup="vGrp"></asp:RegularExpressionValidator>
from MSDN about validationGroup
inside the list view i put a email validation and validation summary, when i press edit it will not validation on client side. how to make it able to validate on client side
<span class="title1">Email Address<span style="margin-left:28px;">:</span></span><span style=" margin-left:100px;">
<asp:TextBox ID="SecurityAnsLabel" runat="server" Text='<%# Bind("EmailAdd") %>' Height="25px" Width="200px"/>
<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="SecurityAnsLabel" ErrorMessage="Invalid Email Format" ForeColor="Red" Text="*" SetFocusOnError="True"></asp:RegularExpressionValidator></span>
Set the ValidationGroup property of all the controls(textbox, regular expression control,the button if there is any) involved in this as same like 'EmailValidate'
Hope this works :)
How do I get my customvalidator for my checkbox cbTermsandcond to display in my validationsummary?
At the moment, the error message is displaying next to the checkbox that's being validated.
<div class="mainbookingcheckboxleft">
<asp:CheckBox ID="cbTermsandcond" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="You must agree with our Terms and Conditions"
onservervalidate="CustomValidator1_ServerValidate">
</asp:CustomValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ShowMessageBox="true" ShowSummary="False" />
</div>
Note, my RequiredFieldValidator controls on my webpage are displaying in the Validation summary as a popup box correctly.
I said in my last question and will say in this one too, basically my username reflects my experience!
I currently have a page with 2 listviews, one of which has a number of controls in the InsertItem template.
One of these controls in particuilar is a DDL and I have a Modal Popup Extender hooked up to it. I want to trigger the MPE only when a particular value(not index) is selected. Here is where I am up to now!
DropDownList ExpenseTypeDDL =
(DropDownList) Expenses.InsertItem.FindControl("ExpenseTypeDDL");
int ExpenseType = (Int32.Parse(ExpenseTypeDDL.SelectedValue.ToString()));
if (ExpenseType == 1)
{
AjaxControlToolkit.ModalPopupExtender mpeMiles =
(AjaxControlToolkit.ModalPopupExtender)Expenses.InsertItem.
FindControl("mpeMiles");
mpeMiles.Show();
}
Above are the contents of the DDL SelectedIndexChanged event. This DDL is based on expense types, I want to target a particular value (db primary key) and then display the modal popup so the user can enter their mileage then do some other stuff after.
Here is my mpe
<cc1:ModalPopupExtender ID ="mpeMiles" TargetControlID ="ExpenseTypeDDL"
runat="server" DropShadow="true" PopupControlID="pnlMiles"
BackgroundCssClass="modalBackground" />
<asp:Panel CssClass="modalPopup" ID="pnlMiles" runat="server"
Height="170px">
<div style="padding: 5px; text-align:center">
<asp:Label ID="lblStart" runat="server">Start location.</asp:Label>
<asp:TextBox ID="txtLocationStart" runat="server" />
<asp:RequiredFieldValidator ID="reqLocation" runat="server"
ErrorMessage="You must enter a start location"
ControlToValidate="txtLocationStart" Display="Dynamic" Text="*" >
</asp:RequiredFieldValidator>
<asp:Label ID="lblDestination" runat="server">Destination.</asp:Label>
<asp:TextBox ID="txtDestination" runat="server" />
<asp:RequiredFieldValidator ID="reqDestination" runat="server"
ErrorMessage="You must enter a destination"
ControlToValidate="txtDestination" Display="Dynamic" Text="*" >
</asp:RequiredFieldValidator>
<asp:Label ID="lblMiles" runat="server">Please enter your Mileage</asp:Label>
<asp:RequiredFieldValidator ID="reqMileage" runat="server"
ErrorMessage="You must enter your mileage" ControlToValidate="txtMiles"
Display="Dynamic" Text="*" ></asp:RequiredFieldValidator>
<asp:TextBox ID="txtMiles" runat="server" />
<br />
<br />
<asp:Button ID="btnMiles_OK" runat="server" Text="Save"
CausesValidation="false" />
<asp:Button ID="btnMiles_Cancel" runat="server" Text="Cancel"
CausesValidation="false"/>
</div>
</asp:Panel>
At the moment the mpe shows as soon as the DDL is clicked, but I want that to happen only for the selected value of 1.
Can someone please tell me what I am doing wrong?
TIA
dotnetnewb
This is happening because you have set up the DDL as target of your modal popup extender - so whenever target index is changed, the dialog is shown. The solution is to have an hidden button and make that a target control for modal popup extender - if your DDL has auto-postback as true then your server side code will check the selected index and popup the dialog.
From user experience perspective, unless you have UpdatePanel on page, this would mean on DDL change, page will refreshed and a dialog will be shown. You can also use modal pop-up javascript API to show/hide on DDL selected index change w/o doing post-back. For example,
$find('mpeMiles').show();