<asp:UpdatePanel runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false"> <ContentTemplate> <fieldset> <asp:TextBox ID="txtContact" runat="server" ForeColor="#999999" value="Contact Number" onfocus="if (this.value == 'Contact Number') {this.value = '';this.style.color = '#000000';}" onblur="if(this.value == '') { this.value='Contact Number';this.style.color ='#999999';}" Width="165px" AutoPostBack="True" ontextchanged="txtContact_TextChanged" ></asp:TextBox> <asp:RequiredFieldValidator ID="rContact" runat="server" ControlToValidate="txtContact" CssClass="failureNotification" ValidationGroup="Contact" ErrorMessage="*"></asp:RequiredFieldValidator> </fieldset> </ContentTemplate> <triggers> <asp:PostBackTrigger ControlID="txtContact" ></asp:PostBackTrigger> </triggers> </asp:UpdatePanel>
protected void txtContact_TextChanged(object sender, EventArgs e) { try { if (txtContact.Text != "Contact Number") { string x = txtContact.Text; double y = Double.Parse(x); txtContact.Text = String.Format("{0:(###) ###-####}", y); } } catch (Exception ex) { txtContact.Text = "Contact Number"; } }
<asp:AsyncPostBackTrigger ControlID="txtContact" EventName="TextChanged" />
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)