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

[Solved] radmenu item causesvalidation

3 Answers 213 Views
Menu
This is a migrated thread and some comments may be shown as answers.
JK
Top achievements
Rank 1
JK asked on 15 May 2008, 09:47 AM
Hi,

I have a menu which consists of 2 items

1. update
2. cancel

This menu sits above a series of forms which need to be filled in, so I have put validation controls on each of the textboxes dropdownlist etc..

The menu wont move the page forward if any of the fields are empty, which is good.  My problem is if the user clicks on cancel the page will not redirect (controlled in c# code on "menu_itemclick") this is because the menu control is set to Causesvalidation = true.

Now this is a catch 22, as I need validation on to ensure you cannot update the forms without all the data, but at the same time I need validation off so I can redirect the page if they cancel.

I was looking for a causes validation option on the item in the builder, but as I though it didnt exist as its part of the overall object.

Has anyone got a solution to this very simple requirement?

Thanks,

Jon

3 Answers, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 15 May 2008, 11:01 AM
Hi JK,

Please find below a sample code snippet  that shows the needed approach.

<form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
 
    <script type="text/javascript">  
    function test(sender, e)  
    {  
        if(e.get_item().get_text() == "Update")  
        {  
            var myValidator = $get('<%= RequiredFieldValidator1.ClientID %>');  
            ValidatorEnable(myValidator, true);  
            if(!Page_IsValid)  
            {  
                e.set_cancel(true);  
            }  
        }  
    }  
    </script> 
 
    <telerik:RadMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick" OnClientItemClicking="test">  
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
        <Items> 
            <telerik:RadMenuItem runat="server" Text="Select Operation:">  
                <Items> 
                    <telerik:RadMenuItem runat="server" Text="Update">  
                    </telerik:RadMenuItem> 
                    <telerik:RadMenuItem runat="server" Text="Cancel">  
                    </telerik:RadMenuItem> 
                </Items> 
            </telerik:RadMenuItem> 
        </Items> 
    </telerik:RadMenu> 
    <asp:TextBox ID="TextBox1" runat="server" ValidationGroup="update"></asp:TextBox> 
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" ValidationGroup="update" Enabled="true"></asp:RequiredFieldValidator> 
</form> 



Sincerely yours,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
JK
Top achievements
Rank 1
answered on 15 May 2008, 12:47 PM
Hi Paul,

there are a large amount of feilds on this form ( screenshots are on the support ticket you have been helping me on 138196).

The javascript would be massive as there would be lots of if statements required. Is there another way, say the opposite to the code you have provided, which would be: 

        if(e.get_item().get_text() == "Cancel")  

        {  

            //do something here

            

            

        }  

thanks.

?
0
Paul
Telerik team
answered on 15 May 2008, 01:57 PM
Hi JK,

Unfortunately, there's no more solutions we can offer on that particular case.

Regards,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Menu
Asked by
JK
Top achievements
Rank 1
Answers by
Paul
Telerik team
JK
Top achievements
Rank 1
Share this question
or