Paiscavast
New Member
Using the following template field coding, is it possible to call the Ajax ValidatorCalloutExtenter if the function in my coding that is called FormatPhoneNumber returns the text "Fix Phone Number" from the ItemTemplate? We would also like to stop the DetailsView from updating the database when this happens.\[code\]<asp:TemplateField HeaderText="Primary Phone:" SortExpression="PrimaryPhone"> <EditItemTemplate> <asp:TextBox ID="TextBoxPrimaryPhoneEdit" runat="server" Text='<%# Bind("PrimaryPhone") %>'></asp:TextBox> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBoxPrimaryPhoneInsert" runat="server" Text='<%# Bind("PrimaryPhone") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Literal ID="PrimaryPhoneLiteral" runat="server" Text='<%# IsValidPhoneNumber(Eval("PrimaryPhone").ToString()) %>' /> </ItemTemplate> <ItemStyle ForeColor="Blue" /> </asp:TemplateField>\[/code\]Function that returns the formatted phone.\[code\]Function IsValidPhoneNumber(ByVal pStringToFormat As String) As String If pStringToFormat <> "" Then ' Remove all the grouping characters for ' now. They will be back in later. '--------------------------------------- pStringToFormat = Replace(pStringToFormat, "(", "") pStringToFormat = Replace(pStringToFormat, ")", "") pStringToFormat = Replace(pStringToFormat, "-", "") pStringToFormat = Replace(pStringToFormat, " ", "") pStringToFormat = Replace(pStringToFormat, "X", "x") ' Format according to length. '---------------------------- Try Select Case pStringToFormat.Length Case 7 pStringToFormat = CLng(pStringToFormat).ToString("###-####") Case 10 pStringToFormat = CLng(pStringToFormat).ToString("(###) ###-####") Case Else pStringToFormat = "Fix Phone Number" End Select Catch ex As Exception pStringToFormat = "Fix Phone Number" End Try End If Return pStringToFormatEnd Function\[/code\]