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

Dont Close Edit Form On Button Press

1 Answer 43 Views
Button
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 03 Oct 2012, 02:22 PM
Hello,
I have Grid with Edit mode of "EditForms". When the user clicks the edit button, it brings up an edit tree with two radio buttons with the same group name and two buttons: approve and cancel. By default, neither of the radio buttons are checked. I want to make it so that when the user clicks the approve button and neither radio button is checked, it does not close the edit form.

Here is the radgrid declaration:
<telerik:RadGrid ID="approvalGrid"  runat="server" AllowPaging="true" ShowStatusBar="true" ShowFooter="false" AllowFilteringByColumn="false" FilterItemStyle-HorizontalAlign="Center" ShowGroupPanel="false"
AutoGenerateColumns="false" PageSize="25" AllowSorting="true" AllowMultiRowSelection="false" GirdLines="Vertical" Skin="WebBlue" AlternatingItemStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" GroupingSettings-CaseSensitive="false"  AllowAutomaticInserts="false" AllowAutomaticUpdates="false" AllowAutomaticDeletes="true" OnItemCommand="approvalGrid_ItemCommand"
OnNeedDataSource="approvalGrid_NeedDataSource" OnItemDataBound="approvalGrid_ItemDataBound" Width="1080" EnableLinqExpressions="false">

Here is the edit form:
<EditFormSettings CaptionFormatString=" Approve ID #{0}" CaptionDataField="ID" EditFormType="Template">
<PopUpSettings Modal="false" Width="550px" />
<FormTemplate >
<asp:Label ID="ApprovalWindowError" runat="server" Font-Bold="true" Font-Size="Large" Font-Underline="true" ForeColor="#990000" /<fieldset>
<legend><asp:Label ID="editLabel" runat="server" Text="Select A Location" Font-Bold="true" Font-Size="Medium"></asp:Label> </legend>
<table>                                                           
<tr>
<td align="left">
   Original Location:
</td>                                                               
<td align="left">
<telerik:RadButton ID="SendToOrig" runat="server" ButtonType="ToggleButton" ToggleType="Radio" GroupName="ApproveGroup" Text='<%#Bind("OrigLocation") %>'>
   </telerik:RadButton>
</td>
</tr>
<tr>
<td align="left">
Receiving Location:
 </td>                                                                                                                                 
<td align="left">                                                                   
<telerik:RadButton ID="SendToLocation" runat="server" ButtonType="ToggleButton" ToggleType="Radio" GroupName="ApproveGroup" Text='<%#Bind("Location") %>'>
</telerik:RadButton>                                                               
</td>
</tr>
   </table>
   <table>
<tr>
<td align="right">                                                                   
<telerik:RadButton ID="approveButton" runat="server" Text="Approve" Font-Bold="true" CommandName="Update"></telerik:RadButton>
<telerik:RadButton ID="cancelButton" runat="server" Text="Cancel" Font-Bold="true" CommandName="Cancel"></telerik:RadButton>
</td>
</tr>
</table>
</fieldset>                                                       
</FormTemplate>
</EditFormSettings>

here is the code for the approveButton:
protected void approvalGrid_ItemCommand(object sender, GridCommandEventArgs e)
    {
         
        if (e.CommandName == "Update")
        {                           
            GridEditableItem item = e.Item as GridEditableItem;
            //checks if at least one radio is pushed
            if ((item.FindControl("SendToOrig") as RadButton).Checked || (item.FindControl("SendToLocation") as RadButton).Checked)
            {
                if ((item.FindControl("SendToOrig") as RadButton).Checked)
                {
                    successLabel.Text = "Adjustment Approved For Original Location";                                      
                }
                else
                {
                    successLabel.Text = "Adjustment Approved For Receiving Location";
                }
            }
            //if neither radios are pushed
            else
            {
                errorLabel.Text = "Approval Failed: You Did Not Select A Location";
            }
        }
        if (e.CommandName == "Cancel")
        {
            errorLabel.Text = "Approval Canceled";
        }
    }

Thanks,
Justin

1 Answer, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 08 Oct 2012, 10:03 AM
Hello Justin,

You can add a Custom Validator in the Edit Form template that will check the status of the two radio RadButtons and validate the page only if at least one of them is checked. If you use this control and implement its client-side validation, you will not be able to click the approve button when both radio buttons are unchecked.

All the best,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Button
Asked by
Justin
Top achievements
Rank 1
Answers by
Slav
Telerik team
Share this question
or