locked
Masked Edit not working for template field in Detailsview RRS feed

  • Question

  • User-2087919080 posted

    The Update is accepting whatever is put in the textbox.  Can someone see why this might be happening?

    <asp:TemplateField HeaderText="Phone 1" SortExpression="EmgPh1">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:TextBox>
                                                        <br />
                                                        <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox2"
                                                            Mask="(999)999-9999">
                                                        </ajaxToolkit:MaskedEditExtender>
                                                    </EditItemTemplate>
                                                    <InsertItemTemplate>
                                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:TextBox><br />
                                                        <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox2"
                                                            Mask="(999)999-9999">
                                                        </ajaxToolkit:MaskedEditExtender>
                                                    </InsertItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>

    Thursday, July 3, 2014 1:08 PM

All replies

  • User-1360095595 posted

    Try adding masktype="Number"

    You might also consider using a maskededitvalidator in tandem. 

    Thursday, July 3, 2014 1:27 PM
  • User-2087919080 posted

    same result.  Also, what is 'tandem'?  Also, here is the complete code to help see if there is something else that might help.

    <%@ Page Title="" Language="VB" MasterPageFile="~/Secure/MasterPage.master" AutoEventWireup="false"
        CodeFile="Contacts.aspx.vb" Inherits="Secure_Contacts" %>
    
    <%@ Register Namespace="CustomControls" TagPrefix="cc1" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
                                <asp:ScriptManager ID="ScriptManager1" runat="server">
                                </asp:ScriptManager>
                                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                  <ContentTemplate>
                                  
                                        <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
                                            DataKeyNames="EmgId" DataSourceID="SqlDataSource1" Font-Names="Arial" Font-Size="12pt"
                                            Height="50px" Width="125px" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
                                            AutoGenerateInsertButton="True" CellPadding="4">
                                            <RowStyle Wrap="False" />
                                            <FieldHeaderStyle BackColor="#DCE4EF" Font-Bold="True" Wrap="False" HorizontalAlign="Right" />
                                            <Fields>
                                                <asp:BoundField DataField="EmgId" HeaderText="EmgId" SortExpression="EmgId" Visible="false" />
                                                <asp:TemplateField HeaderText="First Name" SortExpression="EmgFirstName">
                                                    <EditItemTemplate>
                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
                                                            ErrorMessage="RequiredFieldValidator" BackColor="White"></asp:RequiredFieldValidator>
                                                        <br />
                                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("EmgFirstName") %>'></asp:TextBox>
                                                    </EditItemTemplate>
                                                    <InsertItemTemplate>
                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
                                                            ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                                                        <br />
                                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("EmgFirstName") %>'></asp:TextBox>
                                                    </InsertItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("EmgFirstName") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="EmgLastName" HeaderText="Last Name" SortExpression="EmgLastName" />
                                                <asp:BoundField DataField="EmgAdd" HeaderText="Address" SortExpression="EmgAdd" />
                                                <asp:BoundField DataField="EmgCity" HeaderText="City" SortExpression="EmgCity" />
                                                <asp:BoundField DataField="EmgSt" HeaderText="State" SortExpression="EmgSt" />
                                                <asp:BoundField DataField="EmgZip" HeaderText="Zip Code" SortExpression="EmgZip" />
                                                <asp:TemplateField HeaderText="Phone 1" SortExpression="EmgPh1">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:TextBox>
                                                        <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox2"
                                                            Mask="(999)999-9999" MaskType="Number">
                                </ajaxToolkit:MaskedEditExtender>
                                                    </EditItemTemplate>
                                                    <InsertItemTemplate>
                                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:TextBox><br />
                                                        <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox2"
                                                            Mask="(999)999-9999" MaskType="Number">
                                </ajaxToolkit:MaskedEditExtender>
                                                    </InsertItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="EmgPh2" HeaderText="Phone 2" SortExpression="EmgPh2" />
                                                <asp:BoundField DataField="EmgEmail" HeaderText="Email" SortExpression="EmgEmail" />
                                                <asp:BoundField DataField="MemId" Visible="false" HeaderText="MemId" SortExpression="MemId" />
                                                <asp:BoundField DataField="IPAddress" HeaderText="IPAddress" Visible="false" SortExpression="IPAddress" />
                                                <asp:BoundField DataField="Date" HeaderText="Date" Visible="false" SortExpression="Date" />
                                                <asp:BoundField DataField="UserID" HeaderText="UserID" Visible="false" SortExpression="UserID" />
                                                <asp:BoundField DataField="ExtIPAdd" HeaderText="ExtIPAdd" Visible="false" SortExpression="ExtIPAdd" />
                                            </Fields>
                                        </asp:DetailsView>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                       
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>"
                        DeleteCommand="DELETE FROM [Contacts] 
                                OUTPUT deleted.EmgId, deleted.EmgFirstName, deleted.EmgLastName,
                                  deleted.EmgAdd, deleted.EmgCity, deleted.EmgSt, deleted.EmgZip, deleted.EmgPh1, 
                                  deleted.EmgPh2, deleted.EmgEmail, deleted.MemId, deleted.IPAddress, deleted.Date, deleted.UserID, 
                                  deleted.ExtIPAdd, 'Delete', getutcdate() INTO ContactHist 
                                WHERE [EmgId] = @EmgId" InsertCommand="INSERT INTO [Contacts] ([EmgFirstName], [EmgLastName], 
                                [EmgAdd], [EmgCity], [EmgSt], [EmgZip], [EmgPh1], [EmgPh2], [EmgEmail], 
                                [MemId], [IPAddress], [Date], [UserID], [ExtIPAdd]) 
                                OUTPUT inserted.EmgId, inserted.EmgFirstName, inserted.EmgLastName,
                                  inserted.EmgAdd, inserted.EmgCity, inserted.EmgSt, inserted.EmgZip, inserted.EmgPh1, 
                                  inserted.EmgPh2, inserted.EmgEmail, inserted.MemId, inserted.IPAddress, inserted.Date, inserted.UserID, 
                                  inserted.ExtIPAdd, 'Insert', getutcdate() INTO ContactHist 
                                VALUES (@EmgFirstName, 
                                @EmgLastName, @EmgAdd, @EmgCity, @EmgSt, @EmgZip, @EmgPh1, @EmgPh2, @EmgEmail, 
                                @MemId, @IPAddress, @Date, @UserID, @ExtIPAdd)" SelectCommand="SELECT EmgId, EmgFirstName, EmgLastName, 
                                EmgAdd, EmgCity, EmgSt, EmgZip, 
                                EmgPh1, EmgPh2, EmgEmail, MemId, IPAddress, Date, UserID, ExtIPAdd 
                                FROM Contacts WHERE (MemId = @MemId)" UpdateCommand="UPDATE [Contacts] SET [EmgFirstName] = @EmgFirstName, 
                                [EmgLastName] = @EmgLastName, [EmgAdd] = @EmgAdd, [EmgCity] = @EmgCity, 
                                [EmgSt] = @EmgSt, [EmgZip] = @EmgZip, [EmgPh1] = @EmgPh1, [EmgPh2] = @EmgPh2, 
                                [EmgEmail] = @EmgEmail, [MemId] = @MemId, [IPAddress] = @IPAddress, 
                                [Date] = @Date, [UserID] = @UserID, [ExtIPAdd] = @ExtIPAdd 
                                OUTPUT inserted.EmgId, inserted.EmgFirstName, inserted.EmgLastName,
                                  inserted.EmgAdd, inserted.EmgCity, inserted.EmgSt, inserted.EmgZip, inserted.EmgPh1, 
                                  inserted.EmgPh2, inserted.EmgEmail, inserted.MemId, inserted.IPAddress, inserted.Date, inserted.UserID, 
                                  inserted.ExtIPAdd, 'Update', getutcdate() INTO ContactHist 
                                WHERE [EmgId] = @EmgId">
                        <SelectParameters>
                            <asp:SessionParameter Name="MemId" SessionField="MembID" Type="Int32" />
                        </SelectParameters>
                        <DeleteParameters>
                            <asp:Parameter Name="EmgId" Type="Int32" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="EmgFirstName" Type="String" Size="50" />
                            <asp:Parameter Name="EmgLastName" Type="String" Size="50" />
                            <asp:Parameter Name="EmgAdd" Type="String" Size="50" />
                            <asp:Parameter Name="EmgCity" Type="String" Size="50" />
                            <asp:Parameter Name="EmgSt" Type="String" Size="50" />
                            <asp:Parameter Name="EmgZip" Type="String" Size="50" />
                            <asp:Parameter Name="EmgPh1" Type="String" Size="50" />
                            <asp:Parameter Name="EmgPh2" Type="String" Size="50" />
                            <asp:Parameter Name="EmgEmail" Type="String" Size="100" />
                            <asp:SessionParameter Name="MemId" SessionField="MembId" Type="Int32" />
                            <asp:Parameter Name="Date" Type="DateTime" />
                            <cc1:UserExIpParameter Name="ExtIPAdd" />
                            <cc1:UserIpParameter Name="IPAddress" />
                            <cc1:UserUserIdParameter Name="UserID" />
                            <asp:Parameter Name="EmgId" Type="Int32" />
                        </UpdateParameters>
                        <InsertParameters>
                            <asp:Parameter Name="EmgFirstName" Type="String" Size="50" />
                            <asp:Parameter Name="EmgLastName" Type="String" Size="50" />
                            <asp:Parameter Name="EmgAdd" Type="String" Size="50" />
                            <asp:Parameter Name="EmgCity" Type="String" Size="50" />
                            <asp:Parameter Name="EmgSt" Type="String" Size="50" />
                            <asp:Parameter Name="EmgZip" Type="String" Size="50" />
                            <asp:Parameter Name="EmgPh1" Type="String" Size="50" />
                            <asp:Parameter Name="EmgPh2" Type="String" Size="50" />
                            <asp:Parameter Name="EmgEmail" Type="String" Size="100" />
                            <asp:SessionParameter Name="MemId" SessionField="MembId" Type="Int32" />
                            <asp:Parameter Name="Date" Type="DateTime" />
                            <cc1:UserExIpParameter Name="ExtIPAdd" />
                            <cc1:UserIpParameter Name="IPAddress" />
                            <cc1:UserUserIdParameter Name="UserID" />
                        </InsertParameters>
                    </asp:SqlDataSource>
                </asp:Content>
    

    Thursday, July 3, 2014 1:40 PM
  • User-2087919080 posted

    With this - When I click 'Update', nothing happens....no error, no postback, nothing....it just sits in Edit mode.  I can 'Cancel' and it responds accordingly.  Any idea?

    <asp:TemplateField HeaderText="Phone 1" SortExpression="EmgPh1">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:TextBox>
                                                        <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox2"
                                                        ClearMaskOnLostFocus="False" MaskType="Number" Mask="(999) 999-9999">
                                                        </ajaxToolkit:MaskedEditExtender>
                                                        <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlToValidate="TextBox2" 
                                                        ValidationExpression="\(\d{3}\)\s\d{3}\-\d{4}" ControlExtender="MaskedEditExtender1"></ajaxToolkit:MaskedEditValidator>
                                                    </EditItemTemplate>
                                                    <InsertItemTemplate>
                                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:TextBox><br />
                                                    </InsertItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("EmgPh1") %>'></asp:Label>
                                                    </ItemTemplate>
                                                </asp:TemplateField>

    Thursday, July 3, 2014 4:21 PM
  • User-417640953 posted

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
                                <asp:ScriptManager ID="ScriptManager1" runat="server">
                                </asp:ScriptManager>

    Hi mjta,

    Please try to use the ToolkitScriptManager to replace the ScriptManager in your content page.

    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>

    Hope this helps, thanks.

    Best Regards!

    Friday, July 4, 2014 3:51 AM
  • User-1360095595 posted

    Refer here: http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx

    There are several properties on the validator you can set to display various messages to let the user know what he needs to enter. 

    Friday, July 4, 2014 3:56 AM