<%# Page Language="C#" AutoEventWireup="true" CodeFile="Calculator.aspx.cs" Inherits="Calculator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Stats Calculator</title>
<style>
body {
background-color: powderblue;
}
h4 {
font-weight: normal;
}
</style>
</head>
<body>
<h1>Statistics Calculator</h1>
<p>Enter three numbers and click the Submit button to find out the statistics</p>
<form id="form1" runat="server">
<div>
<b>
<asp:Label ID="FirstNumber" runat="server" Text="First Number: " AssociatedControlID="TextBox1"></asp:Label></b>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="required1" runat="server" ControlToValidate="TextBox1" ForeColor="Red" ErrorMessage="*">
</asp:RequiredFieldValidator>
<br />
<br />
<asp:RegularExpressionValidator
ID="regex1"
ControlToValidate="TextBox1"
ValidationExpression="((\d+)((\.\d{1,2})?))$"
ErrorMessage="Input string is not in correct format"
Text="Input string is not in correct format"
ForeColor="Red"
runat="server">
</asp:RegularExpressionValidator>
<br />
<b>
<asp:Label ID="SecondNumber" runat="server" Text="Second Number: " AssociatedControlID="TextBox2"></asp:Label></b>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="required2" runat="server" ControlToValidate="TextBox2" ForeColor="Red" ErrorMessage="*">
</asp:RequiredFieldValidator>
<br />
<br />
<asp:RegularExpressionValidator
ID="regex2"
ControlToValidate="TextBox2"
ValidationExpression="((\d+)((\.\d{1,2})?))$"
ErrorMessage="Input is not in correct format"
Text="Input string is not in correct format"
ForeColor="Red"
runat="server">
</asp:RegularExpressionValidator>
<br />
<b>
<asp:Label ID="ThirdNumber" runat="server" Text="Third Number: " AssociatedControlID="TextBox3"></asp:Label></b>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="required3" runat="server" ControlToValidate="TextBox3" ForeColor="Red" ErrorMessage="*">
</asp:RequiredFieldValidator>
<br />
<br />
<asp:RegularExpressionValidator
ID="regex3"
ControlToValidate="TextBox3"
ValidationExpression="((\d+)((\.\d{1,2})?))$"
ErrorMessage="Input is not in correct format"
Text="Input string is not in correct format"
ForeColor="Red"
runat="server">
</asp:RegularExpressionValidator>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" OnClick="submit" Text="Submit" />
<h1>    Statistics of the numbers you entered</h1>
<h4>    <b>Maximum:</b> <asp:Label ID="Label4" runat="server"></asp:Label></h4>
<h4>   <b>Minimum:</b> <asp:Label ID="Label3" runat="server"></asp:Label></h4>
<h4>    <b>Average:</b> <asp:Label ID="Label2" runat="server"></asp:Label></h4>
<h4>    <b>Total:</b> <asp:Label ID="Label1" runat="server"></asp:Label></h4>
</div>
</form>
</body>
</html>
Here I have an ASP.net form with validation, althought I would like to know how I would be able to display an error message for all fields if any of the values are not valid. What would be the best way to do this ?
Related
I have this webform with 3 AutoCompleteExtenders using the AjaxControlToolkit. The first one deals with customers from a database and that works very well. I have place 2 others in a gridview, AutoCompleteExtenders 2 and 3 to fetch items. For some reason, these do not work and a breakpoint in Items.asmx does not reach when running the code. I have setup these 2 extenders same as the customer one.
What am I doing wrong? I have searched articles online on use in gridviews but am unable to find the issue.
I have
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
in the masterpage.
Code in webform:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PipemanWebPortal.Views.PurchaseOrders.Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>Add Purchase Order</h2>
<script type="text/javascript">
$(document).ready(function () {
window.setTimeout(function () {
$(".alert").fadeTo(1500, 0).slideUp(500, function () {
$(this).remove();
});
}, 3000);
});
// On Page Load
$(function () {
SetDatePicker();
});
// On UpdatePanel Refresh
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
SetDatePicker();
$(".datepicker-orient-bottom").hide();
}
});
};
function SetDatePicker() {
$('#datetimepicker').datepicker
({
format: 'dd.MM.yyyy',
inline: true,
todayHighlight: true,
autoclose: true
});
}
</script>
<div runat="server" visible="false" id="AlertDanger" class="alert alert-danger">
×
<strong>You must choose a date</strong>
</div>
<div runat="server" visible="false" id="AlertSuccess" class="alert alert-success">
×
<strong>Purchase requisition saved successfully</strong>
</div>
<asp:Panel ID="PODetails" runat="server">
<div>
<asp:UpdatePanel ID="UpdatePanelPO" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" BackColor="#E6E6E6">
<fieldset class="form-horizontal">
<div class="row">
<div class="form-group col-sm-6">
<asp:Label runat="server" CssClass="col-sm-6 control-label">Required Date</asp:Label>
<div class="col-sm-6">
<div class="input-group date" id="datetimepicker">
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
<asp:TextBox ID="txtRequiredDate" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtRequiredDate" Display="Dynamic"
CssClass="text-danger" ErrorMessage="The Required Date field is required." />
</div>
</div>
</div>
<div class="form-group col-sm-6">
<asp:Label runat="server" CssClass="col-sm-6 control-label">No.</asp:Label>
<div class="col-sm-6">
<asp:Label ID="lblDocNum" runat="server" CssClass="form-control"></asp:Label>
</div>
</div>
</div>
</fieldset>
<fieldset class="form-horizontal">
<div class="row">
<div class="form-group col-sm-6">
<asp:Label runat="server" CssClass="col-sm-6 control-label" class="">Cust. PO No.</asp:Label>
<div class="col-sm-6">
<div class="input-group">
<asp:TextBox ID="txtPurchaseOrderNo" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtPurchaseOrderNo" Display="Dynamic"
CssClass="text-danger" ErrorMessage="The Cust. Purchase Order No field is required." />
</div>
</div>
</div>
<div class="form-group col-sm-6">
<asp:Label runat="server" CssClass="col-sm-6 control-label">Contact</asp:Label>
<div class="col-sm-6">
<div class="input-group">
<asp:TextBox ID="txtContact" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtContact" Display="Dynamic"
CssClass="text-danger" ErrorMessage="The Contact field is required." />
</div>
</div>
</div>
</div>
</fieldset>
<fieldset class="form-horizontal">
<div class="row">
<div class="form-group col-sm-3">
<asp:Label runat="server" CssClass="col-sm-12 control-label" class="">Customer Name</asp:Label>
</div>
<div class="form-group col-sm-9">
<asp:TextBox ID="txtCustomer" runat="server" CssClass="form-control"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="txtCustomer"
ServicePath="../../Web_Service/Customers.asmx"
ServiceMethod="GetCustomers"
MinimumPrefixLength="2"
EnableCaching="true"
CompletionSetCount="10"
CompletionInterval="10"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
</ajaxToolkit:AutoCompleteExtender>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtCustomer" Display="Dynamic"
CssClass="text-danger" ErrorMessage="The Customer field is required." />
</div>
</div>
</div>
</fieldset>
</asp:Panel>
<asp:GridView ID="pOGridView"
runat="server"
AutoGenerateColumns="False"
AllowPaging="True"
AllowSorting="True"
ShowFooter="True"
OnRowEditing="pOGridView_RowEditing"
OnRowUpdating="pOGridView_RowUpdating"
OnPageIndexChanging="pOGridView_PageIndexChanging"
OnRowCancelingEdit="pOGridView_RowCancelingEdit"
PagerStyle-CssClass="bs-pagination"
ShowHeaderWhenEmpty="True"
EmptyDataText="No Records Found"
CssClass="table table-striped table-bordered table-hover table-condensed">
<Columns>
<asp:TemplateField ItemStyle-Width="30px" HeaderText="#">
<ItemTemplate>
<asp:Label ID="lblLineNum" Text='<%# Container.DataItemIndex + 1 %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="120px" HeaderText="Item">
<ItemTemplate>
<asp:Label ID="lblItem" runat="server"
Text='<%# Bind("Item")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtItem" runat="server" Width="300px" Text='<%# Bind("Item")%>'></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="AutoCompleteExtender2"
runat="server"
TargetControlID="txtItem"
ServicePath="../../Web_Service/Items.asmx"
ServiceMethod="GetItems"
MinimumPrefixLength="2"
EnableCaching="true"
CompletionSetCount="10"
CompletionInterval="10"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
</ajaxToolkit:AutoCompleteExtender>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtItem" Display="Dynamic" ValidationGroup="Edit"
CssClass="text-danger" ErrorMessage="The Item field is required." />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItem" runat="server" Width="300px"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="AutoCompleteExtender3"
runat="server"
TargetControlID="txtItem"
ServicePath="../../Web_Service/Items.asmx"
ServiceMethod="GetItems"
MinimumPrefixLength="2"
EnableCaching="true"
CompletionSetCount="10"
CompletionInterval="10"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
</ajaxToolkit:AutoCompleteExtender>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtItem" Display="Dynamic" ValidationGroup="Insert"
CssClass="text-danger" InitialValue="-1" ErrorMessage="The Item field is required." />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="60px" HeaderText="Qty.">
<ItemTemplate>
<asp:Label ID="lblQuantity" runat="server"
Text='<%# Bind("Quantity")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" Width="100px"
Text='<%# Bind("Quantity")%>'></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtQuantity" Display="Dynamic" ValidationGroup="Edit"
CssClass="text-danger" ErrorMessage="The Quantity field is required." />
<asp:RegularExpressionValidator ControlToValidate="txtQuantity" runat="server" CssClass="text-danger" Display="Dynamic"
ErrorMessage="Only integers allowed." ValidationExpression="^(0|[1-9]\d*)$"
ValidationGroup="Edit"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtQuantity" runat="server" Width="100px"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtQuantity" Display="Dynamic" ValidationGroup="Insert"
CssClass="text-danger" ErrorMessage="The Quantity field is required." />
<asp:RegularExpressionValidator ControlToValidate="txtQuantity" runat="server" CssClass="text-danger" Display="Dynamic"
ErrorMessage="Only integers allowed." ValidationExpression="^(0|[1-9]\d*)$"
ValidationGroup="Insert"></asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="80px" HeaderText="Unit Price">
<ItemTemplate>
<asp:Label ID="lblUnitPrice" runat="server"
Text='<%# Bind("UnitPrice")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtUnitPrice" runat="server" Width="100px"
Text='<%# Bind("UnitPrice")%>'></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtUnitPrice" Display="Dynamic" ValidationGroup="Edit"
CssClass="text-danger" ErrorMessage="The Unit Price is required." />
<asp:RegularExpressionValidator ControlToValidate="txtUnitPrice" runat="server" CssClass="text-danger" Display="Dynamic"
ErrorMessage="Only numbers allowed." ValidationExpression="^[0-9]{0,6}(\.[0-9]{1,2})?$"
ValidationGroup="Edit"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtUnitPrice" runat="server" Width="100px"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtUnitPrice" Display="Dynamic" ValidationGroup="Insert"
CssClass="text-danger" ErrorMessage="The Unit Price is required." />
<asp:RegularExpressionValidator ControlToValidate="txtUnitPrice" runat="server" CssClass="text-danger" Display="Dynamic"
ErrorMessage="Only numbers allowed." ValidationExpression="^[0-9]{0,6}(\.[0-9]{1,2})?$"
ValidationGroup="Insert"></asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="80px" HeaderText="Order Price">
<ItemTemplate>
<asp:Label ID="lblOrderPrice" runat="server"
Text='<%# Bind("OrderPrice")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtOrderPrice" runat="server" Width="100px"
Text='<%# Bind("OrderPrice")%>'></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtOrderPrice" Display="Dynamic" ValidationGroup="Edit"
CssClass="text-danger" ErrorMessage="The Order Price is required." />
<asp:RegularExpressionValidator ControlToValidate="txtOrderPrice" runat="server" CssClass="text-danger" Display="Dynamic"
ErrorMessage="Only numbers allowed." ValidationExpression="^[0-9]{0,6}(\.[0-9]{1,2})?$"
ValidationGroup="Edit"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtOrderPrice" runat="server" Width="100px"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtUnitPrice" Display="Dynamic" ValidationGroup="Insert"
CssClass="text-danger" ErrorMessage="The Order Price is required." />
<asp:RegularExpressionValidator ControlToValidate="txtOrderPrice" runat="server" CssClass="text-danger" Display="Dynamic"
ErrorMessage="Only numbers allowed." ValidationExpression="^[0-9]{0,6}(\.[0-9]{1,2})?$"
ValidationGroup="Insert"></asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ValidationGroup="Edit" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkRemove" runat="server"
CommandArgument='<%# Bind("LineNum")%>'
OnClientClick="return confirm('Are you sure you want to delete this row?')"
Text="Delete" OnClick="DeleteRowPurchaseOrder"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" Text="Add" ValidationGroup="Insert" CssClass="btn btn-primary btn-sm"
OnClick="AddRowPurchaseOrder" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div class="form-group">
<div class="row">
<div class="col-sm-3">
<asp:Button runat="server" ID="InsertButton" OnClick="Insert" Text="Insert" CssClass="btn btn-block btn-primary" />
</div>
<div class="col-sm-3">
<asp:Button runat="server" ID="CancelButton" OnClick="Cancel" Text="Cancel" CausesValidation="false" CssClass="btn btn-block btn-default" />
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Panel>
</asp:Content>
Looks like the other two AutoCompleteExtender are on two different <asp:Panel>, try put on same Panel,
<asp:Panel ID="Panel1" runat="server" BackColor="#E6E6E6">. that's probably the reason why the first one is working, and other two are not.
I am encountering this issue:
asp.net ajax client-side framework failed to load
when I tried to open the modal popup-blocker.
How can I solve this? I've been struggling for weeks...
Here's the code for the same:
<form id="form1" runat="server">
<cc:ToolkitScriptManager ID="sc1" runat="server"></cc:ToolkitScriptManager>
<div>
<asp:Button ID="ModalCall" runat="server" OnClick="ModalCall_Click" Text="ModalCall" />
<cc:ModalPopupExtender ID="mod1" runat="server" CancelControlID="btn1" PopupControlID="pan1" TargetControlID="ModalCall"></cc:ModalPopupExtender>
<asp:Panel ID="pan1" runat="server">
<asp:Button ID="Register" runat="server" OnClick="Register_Click" Text="Register" />
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:TextBox ID="Password" runat="server"></asp:TextBox>
<asp:TextBox ID="ConfirmPassword" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Login" runat="server" OnClick="Login_Click" Text="Login" />
<asp:TextBox ID="LoginEmail" runat="server"></asp:TextBox>
<asp:TextBox ID="LoginPassword" runat="server"></asp:TextBox>
<br />
<asp:Button ID="CallService" runat="server" OnClick="CallService_Click" Text="Call Service" />
<br />
<asp:Button ID="ChangePassword" runat="server" OnClick="ChangePassword_Click" Text="ChangePassword" />
<asp:TextBox ID="OldPassword" runat="server"></asp:TextBox>
<asp:TextBox ID="NewPassword" runat="server"></asp:TextBox>
<asp:TextBox ID="ConfirmChangedPassword" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="btn1" runat="server" Text="hide" />
</asp:Panel>
</div>
</form>
The below code was working fine and i accidentally deleted ajax toolkit and when i reconfigured it its nit showing calender on clicking over text box.please tell me what to do with it .
moreover i request you to reply soon
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/emp.Master" CodeBehind="empleaveapp.aspx.vb" Inherits="abc.WebForm10" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<head />.
<%--
<head id="Head2" runat="server" />.
--%>
<head />.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label1" runat="server" Text="From"></asp:Label>
<asp:TextBox ID="calefrom" runat="server" CssClass="textbox" Height="16px"
Width="157px"></asp:TextBox>
<cc1:CalendarExtender ID="calefrom_CalendarExtender" runat="server"
Enabled="True" TargetControlID="calefrom" Format="yyyy-MM-dd">
</cc1:CalendarExtender>
<asp:CompareValidator ID="CompareValidator2" runat="server"
ControlToCompare="txttdate" ControlToValidate="calefrom" CssClass="active"
ErrorMessage="Please enter a day after today's date"
Operator="GreaterThan" > </asp:CompareValidator>
<br />
<asp:TextBox ID="txttdate" runat="server" Width="1px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="To"></asp:Label>
<asp:TextBox ID="caleto" runat="server" Height="20px" CssClass="textbox"></asp:TextBox>
<cc1:CalendarExtender ID="caleto_CalendarExtender" runat="server"
Enabled="True" TargetControlID="caleto" Format="yyyy-MM-dd">
</cc1:CalendarExtender>
<asp:CompareValidator ID="CompareValidator1" runat="server" Format="yyyy-MM-dd"
ControlToCompare="calefrom" ControlToValidate="caleto"
ErrorMessage="To date can not be smaller then from date"
Operator="GreaterThanEqual"></asp:CompareValidator>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Reason"></asp:Label>
<asp:TextBox ID="txtreason" runat="server"
CssClass="textbox"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtreason"
ErrorMessage="Reason is must for manager to know better"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Send Request" />
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</asp:Content>
It's your ScriptManager. It should be cc1:ToolkitScriptManager and not asp:ScriptManager. You need the toolkit's scripts for the extenders to work.
I have following controls in my page, my CompareValidator works, but not the MaskedEditValidator. Am I missing anything?
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
Date: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server"
Enabled="True" TargetControlID="TextBox1">
</asp:CalendarExtender>
<asp:MaskedEditExtender ID="TextBox1_MaskedEditExtender" runat="server"
CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder=""
CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder=""
CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"
TargetControlID="TextBox1" Mask="99/99/9999" MaskType="Date">
</asp:MaskedEditExtender>
<%--<asp:MaskedEditValidator ID="MaskedEditValidator1" runat="server"
ControlExtender="TextBox1_MaskedEditExtender" ControlToValidate="TextBox1"
ErrorMessage="The Date is not valid!" IsValidEmpty="False">
</asp:MaskedEditValidator>--%>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="Invalid Date!" ControlToValidate="TextBox1"
Operator="DataTypeCheck" Type="Date">
</asp:CompareValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="PostBack"
onclick="Button1_Click" style="height: 26px; width: 85px" />
<br /><br />
Selected Date:<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
Replace your MaskedEditValidator with the following:
<asp:MaskedEditValidator ID="MaskedEditValidator1" runat="server"
ControlExtender="TextBox1_MaskedEditExtender" ControlToValidate="TextBox1"
IsValidEmpty="False" EmptyValueMessage="Invalid Date"
InvalidValueMessage="The Date is not valid!">
</asp:MaskedEditValidator>
The key thing is that you needed InvalidValueMessage and/or EmptyValueMessage instead of ErrorText.
I have a standard button which should call a method but it just refuses to work and I can't figure out why.
ASP code:
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button
ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Change Logo" />
Code behind:
protected void UploadButton_Click(object sender, EventArgs e)
{
PasswordLabel.Visible = true;
PasswordLabel.Text = "TEST Before";
Image_Inserting(this);
PasswordLabel.Text = "TEST After";
}
I just added the textbox methods to test it but it doesn't seem to be posting back (even when I remove Image_Inserting call). All other buttons work fine so I don't know why this one won't work.
EDIT: Whole page- Button code towards the bottom
<%# Page Title="" Language="C#" MasterPageFile="~/Standardmaster.Master" AutoEventWireup="true" CodeBehind="VendorAccount.aspx.cs" Inherits="PetShopParadise.Vendor_Pages.VendorAccount" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.style10
{
color: #FF0000;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
<h2>Account Details</h2>
<div id="RegistrationDiv">
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<EditItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone_Number:
<asp:TextBox ID="Phone_NumberTextBox" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone_Number:
<asp:TextBox ID="Phone_NumberTextBox" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
<br />
Address:
<asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
<br />
Phone Number:
<asp:Label ID="Phone_NumberLabel" runat="server"
Text='<%# Bind("Phone_Number") %>' />
<br />
<asp:Button ID="Button3" runat="server" Text="Edit Details" CommandName="Edit" />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PetShopParadiseConnectionString %>"
SelectCommand="SELECT [Name], [Address], [Phone_Number] FROM [Vendors] WHERE ([VendorID] = #VendorID)">
<SelectParameters>
<asp:SessionParameter Name="VendorID" SessionField="ID" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:Table ID="Table1" runat="server" style="text-align:left;">
<asp:TableRow ID="TableRow4" runat="server">
<asp:TableCell ID="TableCell7" runat="server">Password</asp:TableCell><asp:TableCell ID="TableCell8" runat="server">
<asp:TextBox ID="PasswordBox" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator5"
runat="server"
ControlToValidate="PasswordBox"
Display="None"
Forecolor="Red"
ErrorMessage="Please enter a password." />
</asp:TableCell></asp:TableRow><asp:TableRow ID="TableRow5" runat="server">
<asp:TableCell ID="TableCell9" runat="server">Re-Enter Password</asp:TableCell><asp:TableCell ID="TableCell10" runat="server">
<asp:TextBox ID="PasswordCheckBox" TextMode="Password" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator6"
runat="server"
ControlToValidate="PasswordCheckBox"
Display="None"
Forecolor="Red"
ErrorMessage="Please re-enter your password." />
</asp:TableCell></asp:TableRow></asp:Table><asp:Label
ID="PasswordLabel" runat="server" Text="Password" CssClass="style10"></asp:Label><br />
<asp:Button ID="PasswordButton"
runat="server" Text="Update Password" onclick="PasswordButton_Click" /><br />
<asp:SqlDataSource
ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:PetShopParadiseConnectionString %>"
onselecting="SqlDataSource2_Selecting" SelectCommand="SELECT * FROM Vendors"
UpdateCommand="UPDATE [Vendors] SET [Password]=#passwordhash WHERE ([VendorID] = #VendorID)" OnUpdating="Parameters_Updating">
<UpdateParameters>
<asp:Parameter Name="Password" />
<asp:SessionParameter name="VendorID" sessionfield="ID" />
</UpdateParameters>
</asp:SqlDataSource>
<br /><asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button
ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Change Logo" /></div></asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="bannerContent" runat="server">
</asp:Content>
My guess is that it is causing other (possibly hidden) validation to run. Make sure to set CausesValidation to false.
quote :
*I just added the textbox methods *
I guess our trying to update a Password textBox which you can't.
only by :
PasswordLabel .Attributes["value"] = "aaa";