Header

Tuesday, 11 September 2012

How to find web parts through vb.net


Hi Friedns,

Few days ago i was asked to hide Advaced search web part through one user control's button click.

i was socked how could i find that web parts, and really i wasted too much time to doing this simple task,
bcz i didnt know how to do :(
But we should not give up till get solution :D
and i finaly get solution.

There was a webpart zone in that i added advanced search web part and my Usercontrol through smartPartwithajax features.

so both are in same webpart zone.


Now this is simpl code that we use to find advanceSearchBox

 Public Sub setTab()
        Dim _controls As ControlCollection = Me.Parent.Parent.Controls
            For Each _cde As Control In _controls
                If _cde.GetType().ToString = "Microsoft.Office.Server.Search.WebControls.AdvancedSearchBox" Then
                    Dim _webpart As WebPart = CType(_cde, WebPart)
                    _webpart.Hidden = False
                    Exit For
                End If
           Next
End Sub

Call this function on ur button click on user control u will get solution .


No comments:

Post a Comment