Dilukshan Mahendra
Dilukshan Mahendra

Reputation: 3398

Fire event when selecting a specific Tab Page C#

I have used DevExpress XtraTab Control in one of my Win Form applications, but I want to restrict accessing a tab page based on users permission category, I tried to do it in the following way, where it gives me the message correctly when selecting the tab page but it does not redirecting the user to the specified tab page if he is not authorized and still it lets the unauthorized user to see the tab page.

private void tabInquiryManagement_SelectedPageChanging(object sender, DevExpress.XtraTab.TabPageChangingEventArgs e)
        {
            if(e.Page==xtraTabPage4){

                if(InfoPCMS.user.checkFunctionAuthentication("34")==false){

                    XtraMessageBox.Show(InfoPCMS.message.GET_NOT_AUTHORIZED_ERROR(), "Error");
                    tabInquiryManagement.SelectedTabPage = xtraTabPage1;
                }

            }
        }

//checkFunctionAuthentication returns a boolean based on authorization (false if not authorized)

Please give me a solution

Upvotes: 0

Views: 2003

Answers (1)

Andrey Korneyev
Andrey Korneyev

Reputation: 26856

You should add e.Cancel = true; after showing your messagebox. Actually, you should use this in any *Changing events handlers of DevExpress components if you need to cancel event.

Also consider this approach: if user is not authorized to see some tabpage content - maybe it's better to hide this page from him by setting property of that page PageVisible = false rather that redirect him somewhere?

Upvotes: 1

Related Questions