radmenu item causesvalidation

4 posts, 0 answers
  1. JK
    JK avatar
    123 posts
    Member since:
    Sep 2007

    Posted 15 May 2008 Link to this post

    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
  2. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 15 May 2008 Link to this post

    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
  3. JK
    JK avatar
    123 posts
    Member since:
    Sep 2007

    Posted 15 May 2008 Link to this post

    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.

    ?
  4. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 15 May 2008 Link to this post

    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
Back to Top