hi am using a tab control. in which i have already 3 tabpages. now the problm is that when the form is loaded the first tabepage must be enable while other will be disable to access untill i press the button that first tabpage is contain.
is their solution for my problem. m waiting for reply.

Dani AI

Generated

You do not need to remove and re-add tabs to lock the others. A cleaner WinForms approach is to block navigation until your button on the first tab sets a flag. Handle the TabControl’s Selecting event and cancel any attempt to switch away from TabPage1. This avoids flicker and keeps the other pages fully intact.

' Module-level flag
Private _canNavigate As Boolean = False

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TabControl1.SelectedTab = TabPage1
End Sub

Private Sub TabControl1_Selecting(sender As Object, e As TabControlCancelEventArgs) _
    Handles TabControl1.Selecting
    If Not _canNavigate AndAlso e.TabPage IsNot TabPage1 Then
        e.Cancel = True
    End If
End Sub

' Call this from the button on the first tab when the user is allowed to proceed
Private Sub btnContinue_Click(sender As Object, e As EventArgs) Handles btnContinue.Click
    _canNavigate = True
End Sub

This uses the Selecting event, which fires before the tab changes so you can block it by setting e.Cancel = True. Microsoft documents this pattern explicitly. See TabControl.Selecting event and the reference for TabControlCancelEventArgs.Action/Cancel. If you want the tab header to remain clickable but the content controls to be disabled until the unlock button is pressed, you can set TabPage.Enabled = False and re-enable later; this disables the page’s child controls but does not prevent selecting the tab header. See Microsoft’s guidance under “To programmatically enable or disable all controls on a tab.” Change the appearance of TabControl.

’s remove/add trick works too, but it is usually unnecessary if you cancel selection as above. If this thread is actually about ASP.NET Web Forms with the Ajax Control Toolkit (tags suggest ASP.NET), note that ajaxToolkit:TabPanel supports Enabled="false" to disable a tab, and you can control active tabs via ActiveTabIndex. AjaxControlToolkit Tabs overview.

Recommended Answers

All 2 Replies

You can't disable or hide tabpage in a tabcontrol only tabcontrol can be disabled. this is my problem also. my solution was remove the tabpages and add it again when i need them.

here what i did hope this may help you

private void button2_Click(object sender, EventArgs e)
        {
            if (tabControl1.TabPages.Contains(Secondtabpage))
            {
                return;
            }
            else
            {
                tabControl1.TabPages.Add(Secondtabpage);
            }
        }

when the form loads just remove the other tabs like
tabControl1.TabPages.Remove(Secondtabpage);
tabControl1.TabPages.Remove(Thirdtabpage);

so that the firsttab will be shown. use the above code to show your tabpages again.:

If you can use a free third party tabcontrol then take a look at
TabControlEX which does allow you to disable tabpages as well as a few other
things you can't usually do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.