I'd like to prepopulate my textfield with the following variable:
<%=Membership.GetUser().Email%>
... so that users can submit their email address to my table without having to type it in.
Here is my code:
<form id="form1" runat="server">
<div>
<!-- This is the code for the form. There is a Text Box to collect the first name,
last name and email address. All fields are required and I am validating that the
email address is a valid format. -->
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>First Name: <asp:TextBox ID="txtFirstName"
runat="server" Width="60" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ErrorMessage="Enter First Name" Text="*" ControlToValidate="txtFirstName"
runat="server" />
</asp:TableCell>
<asp:TableCell>Last Name: <asp:TextBox ID="txtLastName" runat="server" Width="60" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtLastName" ErrorMessage="Enter Last Name" Text="*" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Email: <asp:TextBox ID="txtEmail" runat="server" Width="80" />
<asp:RequiredFieldValidator ID="emailRequired"
runat="server" ControlToValidate="txtEmail" ErrorMessage="Email Needs Information"
Text="*"/>
<asp:RegularExpressionValidator ID="emailexpression"
runat="server" ControlToValidate="txtEmail" ValidationExpression=".*#.*\..*"
ErrorMessage="Invalide Email Address" Text="*" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowSummary="true"
ShowMessageBox="true" runat="server" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><asp:Button ID="btnSubmit" runat="server" OnClick="addMember"
CausesValidation="true" Height="30" Width="100" Text="Add Me" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="lblDuplicate" runat="server" Text=""></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
How can I accomplish this?
Pop it in the page load event in the code-behind?
if (!Page.IsPostBack)
{
txtEmail.Text = Membership.GetUser().Email;
}
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 have an ASP.Net 4.6.1 DataList on a web page with methods for both OnItemDataBound and OnItemCreated:
<asp:DataList runat="server" ID="dlAssocDetail" HorizontalAlign="Center" OnEditCommand="dlAssocDetail_EditCommand" OnUpdateCommand="dlAssocDetail_UpdateCommand"
OnCancelCommand="dlAssocDetail_CancelCommand" OnItemCommand="dlAssocDetail_ItemCommand" OnItemDataBound="dlAssocDetail_ItemDataBound" OnItemCreated="dlAssocDetail_ItemCreated">
<ItemTemplate>
<asp:Table runat="server" Font-Names="Arial" HorizontalAlign="Center" CellPadding="20" CellSpacing="20" BackColor="WhiteSmoke" BorderColor="LightGray">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>User ID: </b><asp:Label runat="server" ID="lbEID" Text=<%# Bind("EmployeeID") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Attorney Name: </b><asp:Label runat="server" ID="lbName" Text=<%# Bind("AttorneyName") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Title: </b><asp:Label runat="server" ID="lbTitle" Text=<%# Bind("Title") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Anniversary Date: </b><asp:Label runat="server" ID="lbADate" Text=<%# Bind("AnniversaryDate") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Balance: </b><asp:Label runat="server" ID="lbBalance" Text=<%# Bind("Balance") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Allotment Amount: </b><asp:Label runat="server" ID="lbAAmt" Text=<%# Bind("AllotmentAmount") %> />
</asp:TableCell>
</asp:TableRow>
</asp:Table><br />
<asp:Table runat="server" Font-Names="Arial" HorizontalAlign="Center" CellPadding="20" CellSpacing="20" BackColor="WhiteSmoke" BorderColor="LightGray">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Description: </b><asp:Label runat="server" ID="lbDesc" Text=<%# Bind("Description") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Approved: </b><asp:CheckBox runat="server" ID="cbApproved" Enabled="false" Checked=<%# Bind("Approved") %> />
<b>Rejected: </b><asp:CheckBox runat="server" ID="cbRejected" Enabled="false" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Status: </b><asp:Label runat="server" ID="lbStatus" Text=<%# Bind("OrderStatus") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Request Date: </b><asp:Label runat="server" ID="lbReqDate" Text=<%# Bind("RequestDate") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Order Date: </b><asp:Label runat="server" ID="lbOrderDate" Text=<%# Bind("OrderDate") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Received Date: </b><asp:Label runat="server" ID="lbReceivedDate" Text=<%# Bind("ReceivedDate") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid/Reimb Date: </b><asp:Label runat="server" ID="lbPaidDate" Text=<%# Bind("Paid_ReimbDate") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Total Amount: </b><asp:Label runat="server" ID="lbTotal" Text=<%# Bind("TotalAmount") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid By Firm: </b><asp:Label runat="server" ID="lbByFirm" Text=<%# Bind("Paid_Reimb_Amt_ByFirm") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid By Attorney: </b><asp:Label runat="server" ID="lbByAttorney" Text=<%# Bind("PaidAmountByAttorney") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Operating System: </b><asp:RadioButtonList runat="server" ID="rblOS" Enabled="false" SelectedValue=<%# Bind("OSID") %>
RepeatDirection="Horizontal">
<asp:ListItem Text="Apple" Value="1" />
<asp:ListItem Text="Windows" Value="2" />
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server">
<b>Device Type: </b><asp:RadioButtonList runat="server" ID="rblDType" Enabled="false" SelectedValue=<%# Bind("DeviceTypeID") %>
RepeatDirection="Horizontal">
<asp:ListItem Text="Desktop" Value="1" />
<asp:ListItem Text="Laptop" Value="2" />
<asp:ListItem Text="iPad" Value="3" />
<asp:ListItem Text="Peripheral" Value="4" />
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server" ID="tcSpecs">
<b>Specs: </b><br /><asp:HyperLink runat="server" ID="hlSpecs" Enabled="false" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Upload: </b><asp:FileUpload runat="server" ID="fluUpload" AllowMultiple="true" Enabled="false" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Button runat="server" ID="btnEdit" CommandName="Edit" Text="Edit" Font-Bold="true" Font-Names="Arial"
BackColor="WhiteSmoke" BorderStyle="Outset" Height="40" Width="100" Font-Size="Large" />
<asp:Button runat="server" ID="btnNew" CommandName="New" Text="New" Font-Bold="true" Font-Names="Arial"
BackColor="WhiteSmoke" BorderStyle="Outset" Height="40" Width="100" Font-Size="Large" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server" ColumnSpan="3" HorizontalAlign="Center">
<asp:Label runat="server" ID="lbSuccess" Font-Bold="true" Font-Names="Arial" Font-Size="X-Small" ForeColor="Red" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
<EditItemTemplate>
<asp:Table runat="server" Font-Names="Arial" HorizontalAlign="Center" CellPadding="20" CellSpacing="20" BackColor="WhiteSmoke" BorderColor="LightGray">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>User ID: </b><asp:Label runat="server" ID="lbEID" Text=<%# Bind("EmployeeID") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Attorney Name: </b><asp:Label runat="server" ID="lbName" Text=<%# Bind("AttorneyName") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Title: </b><asp:Label runat="server" ID="lbTitle" Text=<%# Bind("Title") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Anniversary Date: </b><asp:Label runat="server" ID="lbADate" Text=<%# Bind("AnniversaryDate") %> />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Balance: </b><asp:Label runat="server" ID="lbBalance" Text=<%# Bind("Balance") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Allotment Amount: </b><asp:Label runat="server" ID="lbAAmt" Text=<%# Bind("AllotmentAmount") %> />
</asp:TableCell>
</asp:TableRow>
</asp:Table><br />
<asp:Table runat="server" Font-Names="Arial" HorizontalAlign="Center" CellPadding="20" CellSpacing="20" BackColor="WhiteSmoke" BorderColor="LightGray">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Description: </b><asp:TextBox runat="server" ID="tbDesc" Text=<%# Bind("Description") %> />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Approved: </b><asp:CheckBox runat="server" ID="cbApproved" Checked=<%# Bind("Approved") %> />
<b>Rejected: </b><asp:CheckBox runat="server" ID="cbRejected" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Status: </b><asp:DropDownList runat="server" ID="ddlStatus" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Request Date: </b><asp:ImageButton runat="server" ID="ibReqDate" ImageUrl="~/images/Calendar-icon.png" AlternateText="Click here to display calendar" />
<asp:TextBox runat="server" ID="tbReqDate" Text=<%# Bind("RequestDate") %> />
<ajax:CalendarExtender runat="server" ID="ceReqDate" TargetControlID="tbReqDate" PopupButtonID="ibReqDate" />
<asp:ImageButton runat="server" ID="ibDelReqDate" ImageUrl="~/images/cal_nodate.gif" /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+[-/][0-9]+[-/][0-9][0-9][0-9][0-9]$"
ControlToValidate="tbReqDate" ErrorMessage="Correct Format is MM/DD/YYYY" Font-Bold="true" ForeColor="Red"
SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Order Date: </b><asp:ImageButton runat="server" ID="ibOrderDate" ImageUrl="~/images/Calendar-icon.png" AlternateText="Click here to display calendar" />
<asp:TextBox runat="server" ID="tbOrderDate" Text=<%# Bind("OrderDate") %> />
<ajax:CalendarExtender runat="server" ID="ceOrderDate" TargetControlID="tbOrderDate" PopupButtonID="ibOrderDate" />
<asp:ImageButton runat="server" ID="ibDelOrderDate" ImageUrl="~/images/cal_nodate.gif" /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+[-/][0-9]+[-/][0-9][0-9][0-9][0-9]$"
ControlToValidate="tbOrderDate" ErrorMessage="Correct Format is MM/DD/YYYY" Font-Bold="true" ForeColor="Red"
SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Received Date: </b><asp:ImageButton runat="server" ID="ibReceivedDate" ImageUrl="~/images/Calendar-icon.png" AlternateText="Click here to display calendar" />
<asp:TextBox runat="server" ID="tbReceivedDate" Text=<%# Bind("ReceivedDate") %> />
<ajax:CalendarExtender runat="server" ID="ceReceivedDate" TargetControlID="tbReceivedDate" PopupButtonID="ibReceivedDate" />
<asp:ImageButton runat="server" ID="ibDelReceivedDate" ImageUrl="~/images/cal_nodate.gif" /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+[-/][0-9]+[-/][0-9][0-9][0-9][0-9]$"
ControlToValidate="tbReceivedDate" ErrorMessage="Correct Format is MM/DD/YYYY" Font-Bold="true" ForeColor="Red"
SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid/Reimb Date: </b><asp:ImageButton runat="server" ID="ibPaidDate" ImageUrl="~/images/Calendar-icon.png" AlternateText="Click here to display calendar" />
<asp:TextBox runat="server" ID="tbPaidDate" Text=<%# Bind("Paid_ReimbDate") %> />
<ajax:CalendarExtender runat="server" ID="cePaidDate" TargetControlID="tbPaidDate" PopupButtonID="ibPaidDate" />
<asp:ImageButton runat="server" ID="ibDelPaidDate" ImageUrl="~/images/cal_nodate.gif" /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+[-/][0-9]+[-/][0-9][0-9][0-9][0-9]$"
ControlToValidate="tbPaidDate" ErrorMessage="Correct Format is MM/DD/YYYY" Font-Bold="true" ForeColor="Red"
SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Total Amount: </b><asp:TextBox runat="server" ID="tbTotal" Text=<%# Bind("TotalAmount") %> /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+\.{0,1}[0-9]{0,2}$" ControlToValidate="tbTotal"
ErrorMessage="Must be a number" Font-Bold="true" ForeColor="Red" SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid By Firm: </b><asp:TextBox runat="server" ID="tbByFirm" Text=<%# Bind("Paid_Reimb_Amt_ByFirm") %> /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+\.{0,1}[0-9]{0,2}$" ControlToValidate="tbByFirm"
ErrorMessage="Must be a number" Font-Bold="true" ForeColor="Red" SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Paid By Attorney: </b><asp:TextBox runat="server" ID="tbByAttorney" Text=<%# Bind("PaidAmountByAttorney") %> /><br />
<asp:RegularExpressionValidator runat="server" ValidationExpression="^[0-9]+\.{0,1}[0-9]{0,2}$" ControlToValidate="tbByAttorney"
ErrorMessage="Must be a number" Font-Bold="true" ForeColor="Red" SetFocusOnError="true" Font-Size="XX-Small" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<b>Operating System: </b><asp:RadioButtonList runat="server" ID="rblOS" SelectedValue=<%# Bind("OSID") %>
RepeatDirection="Horizontal">
<asp:ListItem Text="Apple" Value="1" />
<asp:ListItem Text="Windows" Value="2" />
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server">
<b>Device Type: </b><asp:RadioButtonList runat="server" ID="rblDType" SelectedValue=<%# Bind("DeviceTypeID") %>
RepeatDirection="Horizontal">
<asp:ListItem Text="Desktop" Value="1" />
<asp:ListItem Text="Laptop" Value="2" />
<asp:ListItem Text="iPad" Value="3" />
<asp:ListItem Text="Peripheral" Value="4" />
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server" ID="tcSpecs">
<b>Specs: </b><asp:HyperLink runat="server" ID="hlSpecs" />
</asp:TableCell>
<asp:TableCell runat="server">
<b>Upload: </b><asp:FileUpload runat="server" ID="fluUpload" AllowMultiple="true" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:Button runat="server" ID="btnUpdate" CommandName="Update" Text="Update" Font-Bold="true" Font-Names="Arial"
BackColor="WhiteSmoke" BorderStyle="Outset" Height="40" Width="100" Font-Size="Large" />
<asp:Button runat="server" ID="btnCancel" CommandName="Cancel" Text="Cancel" Font-Bold="true" Font-Names="Arial"
BackColor="WhiteSmoke" BorderStyle="Outset" Height="40" Width="100" Font-Size="Large" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server">
<asp:TableCell runat="server" ColumnSpan="3" HorizontalAlign="Center">
<asp:Label runat="server" ID="lbSuccess" Font-Bold="true" Font-Names="Arial" Font-Size="X-Small" ForeColor="Red" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</EditItemTemplate>
</asp:DataList>
I'm trying to find a TableCell in the DataList. The ID of the TableCell is tcSpecs. When either the ItemDataBound or ItemCreated event fires, it doesn't see tcSpecs, i.e., tcSpecs remains null. Here's my code:
protected void dlAssocDetail_ItemDataBound(object sender, DataListItemEventArgs e)
{
TableCell tc = (TableCell)e.Item.FindControl("tbSpecs");
}
protected void dlAssocDetail_ItemCreated(object sender, DataListItemEventArgs e)
{
TableCell tc = (TableCell)e.Item.FindControl("tbSpecs");
}
What am I doing wrong? How do I find this TableCell?
Backing up a bit, what I'm trying to accomplish is to dynamically create a bunch of HyperLink controls on the page. I'm trying to find the TableCell so I have somewhere to put them. If anyone can suggest an alternative to using the TableCell, I'm open to that, too. Thanks much.
I figured this out. First you have to find the Table, then the TableRow, then the TableCell. So:
protected void dlAssocDetail_ItemDataBound(object sender, DataListItemEventArgs e)
{
Table ta = (Table)e.Item.FindControl("myTable");
foreach (TableRow row in ta.Rows)
foreach (TableCell cell in row.Cells)
//do something
}
I have a few fields using asp:TemplateField. The code sample for user name and password is below -
<asp:TemplateField HeaderText="User Name" SortExpression="User_Name">
<EditItemTemplate>
<ISEP:PFTextBox ID="User_NameControl" runat="server" Text='<%# Bind("User_Name") %>'
CssClass="DetView TextBox DataWindowControl" />
<asp:Label runat="server" ID ="User_NameRequiredStar" Text="*" CssClass="DetView Label DataWindowControl" ForeColor="Red" style="display: none;"/>
<asp:CustomValidator id="CustomValidatorUserNameExisting" ControlToValidate="User_NameControl" ClientValidationFunction="UserNameExistingValidate"
Display="Static" ErrorMessage="User Name already exists. Please enter a different user name." ForeColor="red" runat="server" Enabled="false"/>
<asp:RequiredFieldValidator
ID="User_NameControlRequiredFieldValidator" runat="server" ControlToValidate="User_NameControl"
ErrorMessage="<%$ AppSettings: RequiredErrorMessage %>" Enabled="false"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="User_NameMaxLengthValidator" runat="server"
ErrorMessage="<%$ AppSettings: MaxLengthErrorMessage %>" ValidationExpression="^(.|\n){0,80}$" ControlToValidate="User_NameControl"></asp:RegularExpressionValidator>
</EditItemTemplate>
<InsertItemTemplate>
<ISEP:PFTextBox ID="User_NameControl" runat="server" Text='<%# Bind("User_Name") %>'
CssClass="DetView TextBox DataWindowControl" />
<asp:Label runat="server" ID ="User_NameRequiredStar" Text="*" CssClass="DetView Label DataWindowControl" ForeColor="Red" style="display: none;"/>
<asp:CustomValidator id="CustomValidatorUserNameExisting" ControlToValidate="User_NameControl" ClientValidationFunction="UserNameExistingValidate"
Display="Static" ErrorMessage="User Name already exists. Please enter a different user name." ForeColor="red" runat="server" Enabled="false"/>
<asp:RequiredFieldValidator
ID="User_NameControlRequiredFieldValidator" runat="server" ControlToValidate="User_NameControl"
ErrorMessage="<%$ AppSettings: RequiredErrorMessage %>" Enabled="false"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="User_NameMaxLengthValidator" runat="server"
ErrorMessage="<%$ AppSettings: MaxLengthErrorMessage %>" ValidationExpression="^(.|\n){0,80}$" ControlToValidate="User_NameControl"></asp:RegularExpressionValidator>
</InsertItemTemplate>
<ItemTemplate>
<ISEP:PFLabel ID="User_NameLabel" runat="server" Text='<%# Bind("User_Name") %>'
CssClass="DetViewText Label DataWindowControl" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" SortExpression="User_Password">
<EditItemTemplate>
<ISEP:PFTextBox ID="User_PasswordControl" TextMode="Password" runat="server" Text='<%# Bind("User_Password") %>'
CssClass="DetView TextBox DataWindowControl" />
<asp:Label runat="server" ID ="User_PasswordRequiredStar" Text="*" CssClass="DetView Label DataWindowControl" ForeColor="Red" style="display: none;"/>
<asp:RequiredFieldValidator
ID="User_PasswordControlRequiredFieldValidator" runat="server" ControlToValidate="User_PasswordControl"
ErrorMessage="<%$ AppSettings: RequiredErrorMessage %>" Enabled="false"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="User_PasswordMaxLengthValidator" runat="server"
ErrorMessage="<%$ AppSettings: MaxLengthErrorMessage %>" ValidationExpression="^(.|\n){0,80}$" ControlToValidate="User_PasswordControl"></asp:RegularExpressionValidator>
</EditItemTemplate>
<InsertItemTemplate>
<ISEP:PFTextBox ID="User_PasswordControl" TextMode="Password" runat="server" Text='<%# Bind("User_Password") %>'
CssClass="DetView TextBox DataWindowControl" />
<asp:Label runat="server" ID ="User_PasswordRequiredStar" Text="*" CssClass="DetView Label DataWindowControl" ForeColor="Red" style="display: none;"/>
<asp:RequiredFieldValidator
ID="User_PasswordControlRequiredFieldValidator" runat="server" ControlToValidate="User_PasswordControl"
ErrorMessage="<%$ AppSettings: RequiredErrorMessage %>" Enabled="false"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="User_PasswordMaxLengthValidator" runat="server"
ErrorMessage="<%$ AppSettings: MaxLengthErrorMessage %>80" ValidationExpression="^(.|\n){0,80}$" ControlToValidate="User_PasswordControl"></asp:RegularExpressionValidator>
</InsertItemTemplate>
</asp:TemplateField>
I do not why User_Name is passed to DetailsViewUpdatedEventArgs and DetailsViewInsertedEventArgs but User_Password is not.
Except for OnItemUpdated and OnItemInserted, where can I debug these fields?
Thanks,
I create textbox for user to choose the date and set the requiredfieldvalidator.
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="StartDate" ErrorMessage="RequiredFieldValidator"
ValidationGroup="Search" SetFocusOnError="True" Display="Dynamic"
ToolTip="*Fill START Date!">*Fill START Date!</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="EndDate" ErrorMessage="RequiredFieldValidator"
ValidationGroup="Search" Display="Dynamic" ToolTip="*Fill END Date!">*Fill END Date!</asp:RequiredFieldValidator>
<asp:Label ID="DateFilter" runat="server"
Text="Filter by Date from :" style="font-family: 'Arial Narrow'"
AssociatedControlID="StartDate"></asp:Label>
<asp:TextBox ID="StartDate" runat="server" ></asp:TextBox>
<a href="javascript:;" onclick="window.open('CalendarPopup.aspx?textbox=StartDate','cal','width=220,height=205,left=270,top=180')"><img id="Img1"
src="calendar-icon.gif" border="0" runat="server" alt="calendar"
style="height: 23px" align="bottom"></a>
<asp:Label ID="Label4" runat="server" Text="to" Font-Names="Arial Narrow"
AssociatedControlID="EndDate"></asp:Label>
<asp:TextBox ID="EndDate" runat="server"></asp:TextBox>
<a href="javascript:;" onclick="window.open('CalendarPopup.aspx?textbox=EndDate','cal','width=220,height=205,left=270,top=180')"><img id="Img2"
src="calendar-icon.gif" border="0" runat="server" alt="calendar"
style="height: 23px" dir="ltr"></a>
<asp:Button
ID="Search" runat="server" BackColor="Black" Font-Names="Arial Narrow"
ForeColor="White" Text="SEARCH" Width="73px" onclick="Search_Click" />
Then, I need to compare the first date must be less than second date using Compare Validator.
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="EndDate" ControlToValidate="StartDate"
ErrorMessage="CompareValidator" Operator="GreaterThanEqual" Type="Date"
ValidationGroup="Search" Display="Dynamic" SetFocusOnError="True">*First date must be less than or equal to Second
date!</asp:CompareValidator>
Both validator are not working. Anyone kindly please help. Thanks..:)
Siti
Update, I didn't see it before, but you need to have the button be a part of the same validation group as your validators. Try this:
<asp:Button ValidationGroup="Search"
ID="Search" runat="server" BackColor="Black" Font-Names="Arial Narrow"
ForeColor="White" Text="SEARCH" Width="73px" onclick="Search_Click" />
Oh, and I'm pretty sure you need the other logic operator I mentioned before because the ControlToValidate is the primary value that gets evaluated against ControlToCompare so ControlToValidate is LessThan ControlToCompare = StartDate is LessThan EndDate:
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="EndDate" ControlToValidate="StartDate"
ErrorMessage="CompareValidator" Operator="LessThan" Type="Date"
ValidationGroup="Search" Display="Dynamic" SetFocusOnError="True">*First date must be less than or equal to Second date!</asp:CompareValidator>
Since you are having problems, I have checked the code in its entirety and this works exactly as it shoul. Copy and paste this:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="StartDate" ErrorMessage="RequiredFieldValidator"
ValidationGroup="Search" SetFocusOnError="True" Display="Dynamic"
ToolTip="*Fill START Date!">*Fill START Date!</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="EndDate" ErrorMessage="*Fill END Date!"
ValidationGroup="Search" Display="Dynamic" ToolTip="*Fill END Date!" />
<asp:Label ID="DateFilter" runat="server"
Text="Filter by Date from :" style="font-family: 'Arial Narrow'"
AssociatedControlID="StartDate"></asp:Label>
<asp:TextBox ID="StartDate" runat="server" ></asp:TextBox>
<a href="javascript:;" onclick="window.open('CalendarPopup.aspx?textbox=StartDate','cal','width=220,height=205,left=270,top=180')"><img id="Img1"
src="calendar-icon.gif" border="0" runat="server" alt="calendar"
style="height: 23px" align="bottom"></a>
<asp:Label ID="Label4" runat="server" Text="to" Font-Names="Arial Narrow"
AssociatedControlID="EndDate"></asp:Label>
<asp:TextBox ID="EndDate" runat="server"></asp:TextBox>
<img id="Img2" src="calendar-icon.gif" border="0" runat="server" alt="calendar" style="height: 23px" dir="ltr">
<asp:Button ValidationGroup="Search"
ID="Search" runat="server" BackColor="Black" Font-Names="Arial Narrow"
ForeColor="White" Text="SEARCH" Width="73px" onclick="Search_Click" />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="EndDate" ControlToValidate="StartDate"
ErrorMessage="CompareValidator" Operator="LessThan" Type="Date"
ValidationGroup="Search" Display="Dynamic" SetFocusOnError="True">*First date must be less than or equal to Second date!</asp:CompareValidator>
~
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.