This is a migrated thread and some comments may be shown as answers.

setting value of dynamically created RadNumericTextBox

1 Answer 130 Views
Input
This is a migrated thread and some comments may be shown as answers.
Morten
Top achievements
Rank 2
Iron
Iron
Veteran
Morten asked on 08 Oct 2010, 10:16 PM
Embedded in an asp:repeater a number of RadNumericTextBoxes and an equal number of required validators for the RadNumericTextBoxes are created:

<asp:Repeater runat="server" ID="rep">
  <ItemTemplate>
  <telerik:RadNumericTextBox id="txt" NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator="" runat="server" Type="Number" />
      <asp:RequiredFieldValidator runat="server" ID="rfv" ControlToValidate="txt">*</asp:RequiredFieldValidator><br />
</asp:Repeater>

On client side I have a jquery-setup checkbox change event handler that should toggle the value of all RadNumericTextBoxes between '' (empty) (when checked) or 0 (zero) (when un-checked):

$(document).ready(function () {
  $("input[name$='chk']").change(function () {
    chk_OnChange(this);
  });
});
 
  function chk_OnChange(sender) {
    if (!sender.checked) {
      $("input[name*='txt']").val('0');
    }
    else {
      $("input[name*='txt']").val('');
    }
  }

So far so good; Values get changed the way I want.

However, when trying to submit the form the required field validators (rfv) fail even if the RadNumericTextBoxes displays 0 (zero).

How can I set the value of the RadNumericTextBoxes so that the required field validators don't fail?

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 12 Oct 2010, 12:41 PM
Hello Morten,

This will work:

$("input[id*='txt']")

However, note that this is not a recommended way to set values to RadNumericTextBoxes. The recommended way is via these controls' API:

http://www.telerik.com/help/aspnet-ajax/input_clientsideradnumerictextbox.html

The API methods are executed over the RadNumericTextBox client object, obtainable with $find(client_id)

http://www.telerik.com/help/aspnet-ajax/input_clientsidebasics.html

All the best,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Input
Asked by
Morten
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Dimo
Telerik team
Share this question
or