We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

how to disable a menu item in menu control?

Hi Friends,
I have a menu this work well, but I must  enabled or disabled each item depending on your authorizations.  Authorizations are in the database, I need that you guide me as I enable or desahilitar the menu by code behind, either hide menu option or disable it

Versión 14.2460.0.26

In advance thank you very much for your help



7 Replies

KC Kasithangam C Syncfusion Team July 27, 2016 11:11 AM UTC

Hi Edwin,   
  
Thanks for contacting Syncfusion support.     
  
We can disable the menu item by using “htmlAttribute” property. “HtmlAttribute” is one of the member in “fields” property. The value specified for the “htmlAttribute” will be included to the corresponding menu item.   
 
We have prepared the sample based on your requirement and you can find the sample under the following location:   

Sample: Sample 

In this sample, we have added the “e-disable-item” class value in “htmlAttribute” property. Please refer the below code to define the class value in the “htmlAttribute” in codebehind.   
<code> 
sites.Add(new menufields { id = "11", parentId = 1, text = "Algeria", sprite = "flag-dz",htmlAttr=new html() { Class="e-disable-item"} });</code> 
Now during control creation, map it to the “htmlAttribute” in fields as shown below, 
<code> 
<ej:Menu ID="sitemenu" DataIdField="id" DataParentIdField="parentId" DataTextField="text" DataSpriteCssField="sprite" DataHtmlAttributeField="htmlAttr" runat="server"></ej:Menu> 
</code> 
To know more details about properties, methods and events of Menu Component, please refer the following API link,   

 
Regards, 
Kasithangam 



ER Edwin Romero July 27, 2016 08:16 PM UTC

thanks for your quick response, I'm sure that it'll be very useful, I have a question else there is a way to change disable or enable if some item of menu is not being created at runtime, i.e. is designed by html I have that menu and want at runtime change (disable or enable) certain ítems;  example, I have menú below I want to disable "mnuUseUser" is there any way?

        <ej:Menu ID="mnuSec" Width="500px" runat="server" AnimationType="Default" DataHtmlAttributeField="htmlAttribute" DataIdField="id" DataImageAttributeField="imageAttribute" DataImageUrlField="imageUrl" DataLinkAttributeField="linkAttribute" DataParentIdField="parentId" DataSourceCachingMode="None" DataSpriteCssField="spriteCssClass" DataTextField="text" DataUrlField="url" MenuType="NormalMenu" meta:resourcekey="SyncfusionProductsResource1" Orientation="Horizontal" SubMenuDirection="None" BorderStyle="Outset">
            <Items>
                <ej:MenuItem ID="mnuPar" Text="Parámetros">
                    <Items>
                        <ej:MenuItem ID="mnuParMod" Text="Módulos">
                        </ej:MenuItem>
                        <ej:MenuItem ID="mnuParPag" Text="Páginas">
                        </ej:MenuItem>
                    </Items>
                </ej:MenuItem>

                <ej:MenuItem Id="mnuUser" Text="Usuarios">

                    <Items>
                        <ej:MenuItem ID="mnuUseRol" Text="Roles">
                        </ej:MenuItem>
                        <ej:MenuItem ID="mnuUseUser" Text="Registro" Url="~/SegRegistro.aspx">
                        </ej:MenuItem>
                        <ej:MenuItem ID="mnuUsePerfil" Text="Perfil de usuario" Url="">
                        </ej:MenuItem>
                    </Items>

                </ej:MenuItem>

            </Items>

        </ej:Menu>

Well In advance thank you very much for your help


KC Kasithangam C Syncfusion Team July 28, 2016 01:21 PM UTC

Hi Edwin, 

Thanks for your update. 

Currently we are not able to disable/enable submenu item while created the menu by html. We have considered this as a bug. Can you please check the incident (161258) for further updates? 

Regards, 
Kasithangam 




ER Edwin Romero July 28, 2016 07:31 PM UTC

Ok thanks a lot Kasithangam 
You've been very helpful. I will periodically review the incident that you refer me

Regards




KC Kasithangam C Syncfusion Team July 29, 2016 04:36 AM UTC

Hi Edwin, 
 
Thanks for your update. Please get back to us if you have further query. We will be happy to help you out. 

Regards, 
Kasithangam 



MP Mike Potratz March 14, 2017 01:50 PM UTC

Has this "bug" been fixed?  If so, are there any examples of using it?


PO Prince Oliver Syncfusion Team March 15, 2017 09:53 AM UTC

Hi Mike,   
   
Thank you for contacting Syncfusion support.   
   
We have fixed it and its available since 2016, volume 2 SP-2 release.   
   
To disable the submenu item, you can access the submenu item by using id and add the HtmlAttribute property in codebehind. Kindly refer to the following code example.   
   
  protected void butt_Click(object sender, EventArgs e)   
  {   
      adsearch.HtmlAttributes = "class=e-disable-item";   
  }   
   
Also, you can use the HtmlAttribute property for sub menu item in menu control. Kindly refer to the following code example.   
   
<ej:MenuItem Id="Resume" Text="Resume writing" HtmlAttributes="class=e-disable-item" Url="~/Contact.aspx"></ej:MenuItem>   
   
If you are using URL attribute in the submenu item, then we need to avoid the URL navigation for a disabled item. This can be done by using jQuery's preventDefault method. Kindly have a look at the following code example.    
   
<ej:MenuItem Id="Resume" Text="Resume writing" Url="~/Contact.aspx"></ej:MenuItem>    
<script>    
        $("#Resume").click(function (event) {    
            event.preventDefault();    
        });    
</script>    
    
Refer to the following link for the sample:    
   
Regards,   
Prince  


Loader.
Live Chat Icon For mobile
Up arrow icon