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

Grid-popup add/edit validations problem

2 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
s
Top achievements
Rank 1
s asked on 15 Sep 2011, 09:25 AM
Hello!

I have some problems with validatng fields through radGrid/popup edit form. The fields to be validated are used in both 'Add' and 'Edit' popups, but validation works only in 'Add' form. Here is my approach. In ascx file:


<th>Amount:</th>
<td><asp:TextBox ID="txtAmount" runat="server" />
 
<asp:CustomValidator ID="ResourceValidator2" runat="server" Display="dynamic" ValidateEmptyText="true"
 ControlToValidate="txtAmount"
 ErrorMessage="Amount has to be entered and it has to be numeric value. "
  OnServerValidate="Validate_RealizationAmount" />
</td>

And on cs file the validation function:

protected void Validate_RealizationAmount(object source, ServerValidateEventArgs args)
       {
           double priceNum;
 
           if (txtAmount.Text == "" ||
               !double.TryParse(txtAmount.Text.Trim(), out priceNum))
           {
               args.IsValid = false;
           }
       }

Aditionally the ascx file is build in a way that the same file defines edit and add forms so that fields used in both are the same. So basically the submit is done by following button definitions:

<asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName='<%# DataItem is Telerik.Web.UI.GridInsertionObject ? "PerformInsert" : "UpdateEdited" %>'>
    <img style="border:0px;vertical-align:middle;" alt="" />
    <%# DataItem is Telerik.Web.UI.GridInsertionObject ? "Add" : "Update"%>
</asp:LinkButton>  
<asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll">
    <img style="border:0px;vertical-align:middle;" alt=""/>Peruuta
</asp:LinkButton>

So, basically when using the 'Add' popup the system prints an error text if the field is not valid, but doesn't do the same when using 'Edit'.  I don't know where to start digging. Help on this would be much appreciated.

-Sami

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Sep 2011, 01:52 PM
Hello,

I guess the Issue is because of the CommandName you have set for Update button in UserControl. Please change the CommandName to 'Update' and check whether this works.

UserControl
<asp:LinkButton ID="btnUpdateEdited" runat="server"
 CommandName='<%# DataItem is Telerik.Web.UI.GridInsertionObject ? "PerformInsert" : "Update" %>'>
    <img style="border:0px;vertical-align:middle;" alt="" />
    <%# DataItem is Telerik.Web.UI.GridInsertionObject ? "Add" : "Update"%>
</asp:LinkButton>

Shinu.
0
s
Top achievements
Rank 1
answered on 21 Sep 2011, 11:43 AM
Thanks for the reply Shinu. I tried the change:

<asp:LinkButton ID="btnUpdateEdited" runat="server"
 Update='<%# DataItem is Telerik.Web.UI.GridInsertionObject ? "PerformInsert" : "Update" %>'>
    <img style="border:0px;vertical-align:middle;" alt="" />
    <%# DataItem is Telerik.Web.UI.GridInsertionObject ? "Add" : "Update"%>
</asp:LinkButton>

Now, in both add and edit popups the validation works, but nothing can be accepted, meaning that nothing happens when I press the Add or Edit button at bottom of the popup. So, it seems that 'CommandName' is the cause of the problem, but I don't know how to fix it. Any further suggestions?

Sami
Tags
Grid
Asked by
s
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
s
Top achievements
Rank 1
Share this question
or