This is a migrated thread and some comments may be shown as answers.

How to you set RadButton in CommandItemTemplate invisible

3 Answers 29 Views
Button
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 08 Oct 2019, 02:13 PM

I have a radbutton in a CommandItemTemplate and I want to be able to set it invisible. I am going to use Active Directory to do a check to see who is using the application and hide the button for basic users. But right now I am just trying to hide the button in the PreRender sub. I am getting an error 'Index was outside the bounds of the array' error.

    <div class="divColumn100">
        <asp:Button ID="HiddenButton" runat="server" Text="HiddenButton" OnClientClick="HiddenButton_Click" Style="display: none;" />
        <telerik:RadToggleButton ID="btnToggleActiveInactive" runat="server" Width="96%" AutoPostBack="true">
            <ToggleStates>
                <telerik:ButtonToggleState Text="Active Drivers" Selected="true" />
                <telerik:ButtonToggleState Text="In-Active Drivers" />
                <telerik:ButtonToggleState Text="Both Active and In-Active Drivers" />
            </ToggleStates>
        </telerik:RadToggleButton>
    </div>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server" IsSticky="true" InitialDelayTime="1000">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel>
    <telerik:RadWindowManager ID="rdwinDrivers" runat="server"></telerik:RadWindowManager>


    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel2"EnablePageHeadUpdate="False" UpdatePanelsRenderMode="Inline">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="HiddenButton">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rdgrdDrivers" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="Panel1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rdgrdBirthDaysMonthly"/>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="rfltMenu">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rdgrdDrivers" UpdatePanelCssClass="" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="rghcMenu">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="rdgrdDrivers" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <div id="demo" class="demo-container no-bg">
        <telerik:RadGrid ID="rdgrdDrivers" runat="server" Skin="Office2010Blue" AutoGenerateColumns="False" AllowPaging="True" PageSize="14" DataSourceID="dsDrivers"
            AllowSorting="True" AllowAutomaticUpdates="True" ShowStatusBar="true" AllowFilteringByColumn="true">
            <GroupingSettings CaseSensitive="false" />
            <SelectedItemStyle CssClass="MySelectedClass" />
            <MasterTableView DataSourceID="dsDrivers" CommandItemDisplay="Top" DataKeyNames="EMP_ID" EditFormSettings-PopUpSettings-KeepInScreenBounds="true" EditMode="PopUp">
                <CommandItemTemplate>
                    <telerik:RadButton ID="btnAddEmp" runat="server"  Text="Add New Employee" CommandName="InitInsert"></telerik:RadButton>
                </CommandItemTemplate>

                <AlternatingItemStyle CssClass="MyRowClass" />
                <EditFormSettings EditFormType="Template">
                </EditFormSettings>

                <Columns>

 

I have this is the PreRender to set the button visible=False.


   Private Sub EmployeeInformation_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
        Dim commandItem As GridCommandItem = CType(rdgrdDrivers.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
        Dim btn As Button = CType(commandItem.FindControl("btnAddEmp"), Button)
        btn.Visible = False
    End Sub

3 Answers, 1 is accepted

Sort by
0
Accepted
Vessy
Telerik team
answered on 11 Oct 2019, 03:04 PM

Hi Dan,

The faced error is related to the fact you are casting the button to asp:Button, but not to RadButton. Changing the provided logic as follows will allow you to hie the add button successfully:

    Protected Sub EmployeeInformation_PreRender(ByVal sender As Object, ByVal e As EventArgs)
        Dim commandItem As GridCommandItem = CType((TryCast(sender, RadGrid)).MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
        Dim btn As RadButton = CType(commandItem.FindControl("btnAddEmp"), RadButton)
        btn.Visible = False

        'Dim commandItem As GridCommandItem = CType(rdgrdDrivers.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
        'Dim btn As Button = CType(commandItem.FindControl("btnAddEmp"), Button)
        'btn.Visible = False
    End Sub

 

Regards,
Vessy
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Dan
Top achievements
Rank 1
answered on 15 Oct 2019, 04:28 PM
Thanks Vessy. I ended up putting in RadGrid ItemDataBound.
    Private Sub rdgrdDrivers_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles rdgrdDrivers.ItemDataBound
        If (TypeOf e.Item Is GridCommandItem) Then 'AndAlso (e.Item.OwnerTableView.Name = "Detractions") Then
            If ADUtil.IsInGroup("ASP_TRANSIT_PAY_USERS") Then 'ASP_TRANSIT_PAY_USERS   ASP_TRANSIT_PAY_ADMIN
                Dim cmditm As GridCommandItem = CType(e.Item, GridCommandItem)
                Dim btnNew As RadButton = CType(cmditm.FindControl("btnAddEmp"), RadButton)
                btnNew.Visible = False
            End If
        End If
    End Sub
0
Vessy
Telerik team
answered on 16 Oct 2019, 11:38 AM

Hi,

Thank you for the update, Dan - I am glad you found a solution that suits your needs.

Regards,
Vessy
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Button
Asked by
Dan
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Dan
Top achievements
Rank 1
Share this question
or