Click here to Skip to main content
15,844,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a page with lots of controls . When i type inside a textbox its format need to be changes to a formatted text. i don't want the whole page to be refreshed. please see my code below...
this is not working...please correct aspx page

<asp:UpdatePanel runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
                                <asp:TextBox ID="txtContact" runat="server"  ForeColor="#999999"
                                    value="Contact Number" onfocus="if (this.value == 'Contact Number')  {this.value = '';  = '#000000';}"

                                    onblur="if(this.value == '') { this.value='Contact Number';  ='#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>
                                    <asp:PostBackTrigger ControlID="txtContact" ></asp:PostBackTrigger>

code behind (aspx.cs)

protected void txtContact_TextChanged(object sender, EventArgs e)
             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";

still the whole page is refeshing...code behind is working perfectly
Updated 4-Aug-13 20:54pm

1 solution

Use AsyncPostBackTrigger instead of PostBackTrigger.

<asp:AsyncPostBackTrigger ControlID="txtContact" EventName="TextChanged" />
Share this answer
Member 10112611 5-Aug-13 2:03am    
now the event TextChanged is not firing
Member 10112611 5-Aug-13 2:03am    
Do i need to chage anything else?
jaideepsinh 5-Aug-13 2:15am    
Make text box autopostback event true.
Member 10112611 5-Aug-13 2:21am    
its already done (AutoPostBack="True" )..before i changing to <asp:AsyncPostBackTrigger ControlID="txtContact" EventName="TextChanged" /> was not working
jaideepsinh 5-Aug-13 2:30am    
Before its working then what is your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900