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

RadNumericTextBox Validation in RadGrid

4 Answers 471 Views
Input
This is a migrated thread and some comments may be shown as answers.
Tiffany
Top achievements
Rank 1
Tiffany asked on 12 Nov 2009, 10:11 PM
Hello,

I'd downloaded the sample code of Iana posted on June 10 from http://www.telerik.com/community/forums/aspnet-ajax/window/window-as-dialog-return-value-in-radgrid-edit-form-template.aspx.  I was able to post back and update the value in the RadNumericTextBox inside the RadGrid control.  However, when I click the Save button on the Insert command, the Required Field validator of the RadNumericTextBox is always failed eventhough the value is set (via set_value method on client side).  I need to make sure the value in the RadNumericTextBox is not empty and is greater than 0. Does any body have experienced this issue as I have?  When I used a regular asp.net textbox, the validator is working fine, but it would be nice if I can use the RadNumbericTextBox in the radgrid in my application.  Could you please tell me what is causing the validator failed here?  Thanks!

Below is my client side code.   I am using RadControls Q1 2009 version.

function ShowUpdateQuantityWin(quantityTxtBxId, nbrPersTextBxId, quantityList) {  
                window.radopen("UpdateQuantity.aspx?quantityList=" + quantityList + "&quanId=" + quantityTxtBxId + "&persId=" + nbrPersTextBxId, "quantityRadWindow");  
                var quantityTxtBx = $find(quantityTxtBxId);   
                quantityTxtBx._textBoxElement.readOnly = false;                  
                return false;  
            }  
 
            function OnQuantityWindowClose(oWnd) {  
                //get the transferred arguments  
                var arg = oWnd.argument;  
                if (arg) {  
                    // alert("arg info: " + arg.quantity + "-" + arg.nbrOfPers + " " + arg.quanId + " " + arg.nbrPersId);  
                    $get('<%=nbrOfPersonsHF.ClientID %>').value = arg.nbrOfPers;  
                    $get(arg.nbrPersId).innerHTML = arg.nbrOfPers;  
                      
                    $get('<%=quantityHF.ClientID %>').value = arg.quantity;  
 
                    $get('<%=quantityListHF.ClientID %>').value = arg.quantityList;  
 
                    var quantityRadTxtBx = $find(arg.quanId);  
                    quantityRadTxtBx.set_value(arg.quantity);                          
                    quantityRadTxtBx._textBoxElement.readOnly  
    }


4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 18 Nov 2009, 08:33 AM
Hi Tiffany,

I followed your scenario and modified the sample accordingly. PLease check it out and let me know if it works as desired or I missed something from your logic out.

Regards,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tiffany
Top achievements
Rank 1
answered on 18 Nov 2009, 03:31 PM

Hi Iana,

Thanks for your quick response.  I'd tried your example and it worked only if the RadNumericTextBox is updatable.  I am sorry for forgetting to tell you that the RadNumericTextBox used in my application is readonly (required by the business requirement).  I was able to replicate the issue using your example by setting the readonly flag to true (see the code below).  I think the validation issue is related to the readonly property of the RadNumericTextBox, but I don't know how to fix it. 

Thanks!

 <script type="text/javascript">  
 
        var textBox = null;  
        function Load(sender, eventArgs)  
        {  
            //assign the current radtextbox's object to the textBox variable  
            textBox = sender;  
        }  
        function openWin()  
        {  
            var oWnd = radopen("Dialog.aspx""RadWindow1");  
            textBox._textBoxElement.readOnly = false;  
        }  
 
        function OnClientClose(sender, args)  
        {  
            var txtargument = args.get_argument();  
            //set the needed value for the currently opened textbox  
            textBox.set_value(txtargument);  
            textBox._textBoxElement.readOnly = true;  
        }  
 
    </script>  
 
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource">  
        <MasterTableView EditMode="InPlace" CommandItemDisplay="Top">  
            <Columns> 
                <telerik:GridBoundColumn DataField="DataField" HeaderText="Data Field" ReadOnly="true">  
                </telerik:GridBoundColumn> 
                <telerik:GridTemplateColumn UniqueName="TemplateColumn">  
                    <EditItemTemplate> 
                        <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" ReadOnly="true">  
                            <ClientEvents OnLoad="Load" /> 
                        </telerik:RadNumericTextBox> 
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="* Required" 
                            ControlToValidate="RadNumericTextBox1"></asp:RequiredFieldValidator> 
                        <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="* Enter value > 0" 
                            ControlToValidate="RadNumericTextBox1" ValueToCompare="0" Operator="GreaterThanEqual"></asp:CompareValidator> 
                        <button onclick="openWin(); return false;">  
                            open RadWindow</button> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridEditCommandColumn> 
                </telerik:GridEditCommandColumn> 
            </Columns> 
        </MasterTableView> 
    </telerik:RadGrid> 

0
Iana Tsolova
Telerik team
answered on 20 Nov 2009, 08:50 AM
Hi Tiffany,

I set the RadNumericTextBox as readonly however, the page continued behaving as expected on my side. Both the Required and Compare validators worked properly. Could you please check it out?

All the best,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Arash
Top achievements
Rank 1
answered on 13 Nov 2010, 07:45 AM
Hi

I have a textbox out of the grid and I need this condition to be permitted  ,when the add button of the grid is clicked:

If (TextBox.Text == String.Empty)
  lblError.Text = "TextBox must be field";

please help
Tags
Input
Asked by
Tiffany
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Tiffany
Top achievements
Rank 1
Arash
Top achievements
Rank 1
Share this question
or