Search code examples
asp.netvb.netcommandlinkbutton

Hide all linkbuttons with CommandArguement="value"


Is there a way to check all linkbuttons that have a specified CommandArgument value and hide/show them in vb.net?

ex:

<asp:LinkButton ID="LinkButton3" runat="server" class="thumbnail" style="text-align:center;" OnClick="display" CommandArgument="App1"/>
<asp:LinkButton ID="LinkButton4" runat="server" class="thumbnail" style="text-align:center;" OnClick="display" CommandArgument="App2"/>
<asp:LinkButton ID="LinkButton5" runat="server" class="thumbnail" style="text-align:center;" OnClick="display" CommandArgument="App1"/>

In vb.net I want to do the following [below is just text of what I want]

for each [Link buttons where CommandArguement = "App1" ]
    Linkbutton[].Visible = false
next

Update:

I tried building something like this but c.CommandArgument doesn't work. I've done a cast on a linkbutton and got the CommandArgument from it but that was after clicking on the linkbutton and returning it which isn't the same scenario as what I am trying to accomplish.

Attempt:

 Dim controlId As String = ""
    Dim cControl As Control

    For Each c As Control In cControl.Controls
        If TypeOf c Is LinkButton Then
            'Or whatever that is you checking for 
            If c.commandArgument = "App1" Then

            End If

        End If
    Next

Example of code that works if I click on it

 Dim btn As LinkButton = DirectCast(sender, LinkButton)
 Dim yourValue As String = btn.CommandArgument

Solution

  • Missed the btn declaration

    Dim c2 As Control
        For Each c2 In pnl1.Controls
            If TypeOf c2 Is LinkButton Then
    
                Dim btn As LinkButton = c2
                Dim val As String = btn.CommandArgument
    
                If val.Contains("App1") Then
    
                End If
            End If
    
        Next