首页 > 解决方案 > How to call a ASPxControl using ASPxMenu's OnItemClick? C#

问题描述

I have a ASPxMenu that I have named "mnuCategoryOptions" and it has 4 items and I also have ASPxPopupControl that I have named "popupAddProductCategory". When I click one of the items in the ASPxMenu I want it to bring up the ASPxPopupControl. I have written my code in the following way and it does not work:

<dx:ASPxMenu ID="mnuCategoryOptions" runat="server" OnItemClick="mnuCategoryOptions_ItemClick">
                                    <ClientSideEvents ItemClick="function(s, e) 
                                    {
                                        e.processOnServer = false;

                                        if (e.item.name == 'mnuAddCategory')  { popupAddProductCategory.Show = true; }
                                        else if (e.item.name == 'mnuEditCategory')  { alert('Edit Category'); }
                                        else if (e.item.name == 'mnuDeleteCategory')  { alert('Del Category'); }
                                        else if (e.item.name == 'mnuAddProducts')  { alert('Add Products'); }
                                        else { e.processOnServer = true; }                
                                    }" />

                                    <Items>
                                        <dx:MenuItem Name="mnuAddCategory"              Text="Add Category"><Image Url="~/images/GridIcons/add.png"/></dx:MenuItem>
                                        <dx:MenuItem Name="mnuEditCategory"              Text="Edit Category"><Image Url="~/images/GridIcons/page_edit.png"/></dx:MenuItem>
                                        <dx:MenuItem Name="mnuDeleteCategory"              Text="Delete Category"><Image Url="~/images/GridIcons/delete.png"/></dx:MenuItem>
                                        <dx:MenuItem Name="mnuAddProducts"         Text="Add Products"><Image Url="~/images/GridIcons/page_add.png"  /></dx:MenuItem>                                                            
                                    </Items>
                                </dx:ASPxMenu>

Please look at the line "if (e.item.name == 'mnuAddCategory') { popupAddProductCategory.Show = true; }". This is the line that is not working. Please help.

Kind Regards Siyabonga Kubeka

标签: asp.netc#-4.0devexpress

解决方案


假设你有这样的ASPxPopupControl服务器控制:

<dx:ASPxPopupControl ID="popupAddProductCategory" runat="server" ClientInstanceName="popupAddProductCategory" ... />

然后你应该使用Show()方法来显示带有客户端代码的弹出窗口:

if (e.item.name == 'mnuAddCategory') { 
    popupAddProductCategory.Show(); 
}

根据ASPxClientPopupControlBase member listShow是方法的名称,而不是属性。如果您想使用与控件名称相同的客户端名称,则还ClientInstanceName必须使用来自弹出控件的属性。

参考:

ASPxClientPopupControlBase.Show() 函数


推荐阅读