0

I have a basic textbox defined as:

@Html.Kendo().TextBoxFor(m => m.myNumber).Format("{0:#,###}").HtmlAttributes(new { @readonly = "readonly", style = "width:150px;" })

After doing an ajax call I update the value via javascript:

$("#myNumber").val(data.myNumber);

However now the formatting is lost, there's no longer a comma thousands separator present. Is there a javascript function I need to call on $("#myNumber"), like a rebind or refresh? For some reason telerik doesn't have any documentation for their textbox.

Legion
  • 3,922
  • 8
  • 51
  • 95
  • Are you able to take in your Data in that format? If it pulls that data in, in the format you want it may remove the need to refresh it. Otherwise, you could make your textbox a partial view and then just refresh the partial view whenever it takes in data, thus setting it back to the correct format. – Kevin Jul 23 '19 at 15:07
  • I think what you're more looking for is the [NumericTextBox](https://docs.telerik.com/aspnet-mvc/api/Kendo.Mvc.UI.Fluent/NumericTextBoxBuilder). This will give you the proper controls of being able to set it's format and then in the javascript after your ajax call, set the value of the **kendo** object to maintain formatting. Right now all you're doing is selecting a plain jQuery html element and setting it's value. That won't interface with the kendo textbox (which isn't an object) at all. You'll either need to return your value in the format you desire or explore @Kevin's option as alts. – Drew B. Jul 23 '19 at 16:02
  • @DrewB. Thanks, setting values through NumericTextBox resolved the issue. – Legion Jul 23 '19 at 16:22

1 Answers1

2

Copying answer from the comments:

I think what you're more looking for is the NumericTextBox. This will give you the proper controls of being able to set it's format and then in the javascript after your ajax call, set the value of the kendo object to maintain formatting. Right now all you're doing is selecting a plain jQuery html element and setting it's value. That won't interface with the kendo textbox (which isn't an object) at all. You'll either need to return your value in the format you desire or explore @Kevin's option as alternatives.

Drew B.
  • 1,145
  • 10
  • 15