Data is not updated when using asp:Literal with string.Format

cyruski

New Member
We are using string.Format("{0:(###) ###-####}" to display formatted phone numbers in a DetailsView. An example of the phone number is:(516) 123-4567\[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='<%# iif(Len(Eval("PrimaryPhone"))=10, string.Format("{0:(###) ###-####}", Int64.Parse(Eval("PrimaryPhone").ToString())), Eval("PrimaryPhone")) %>' /> </ItemTemplate> <ItemStyle ForeColor="Blue" /></asp:TemplateField>\[/code\]It formats nicely when the phone number is exactly 10 numbers and it allows the user to edit the phone. The problem we are getting is when the user erases the phone number and tries to click the Update button. The data is not saved until the user types something into the TextBox even though the database table column does allow nulls.Did I make a mistake in my coding? We would like to set it up in such a way in case the user clears out the phone TextBox prior to clicking the Update button.
 
Back
Top