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

Link button won't keep properties

2 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 30 Oct 2008, 03:51 PM
Hello,

I have a LinkButton in a CommandItemTemplate in a RadGrid. I need to set the visibility of this button to false when the user is not authorized to use certain functionality. I do an authorization check in the Page_load method, and set the visibility to false. this works fine. However when the user clicks on one of the column headers(to sort) the button then shows back up. This doesn't happen to two other columns that I also set the visibility on to false. Is there some grid property I need to set to make this work?

ASP.NET:

<

 

CommandItemTemplate>

 

 

<div class="commandItemButtons">

 

 

<asp:LinkButton ID="addButton" runat="server" CommandName="InitInsert">

 

 

<img class="padding" alt="Add Acronym" src="../App_Themes/Default/TelerikControls/Grid/add.png" />Add Acronym</asp:LinkButton>

 

 

</div>

 

 

</CommandItemTemplate>

 

C#:

 

//Makes a reference to the addButton on the Page

 

 

LinkButton addButton = (WebUtilities.FindControl(acronymRadGrid, "addButton") as LinkButton) ;

 

 

//Administrators get to see all of the columns as well as the add button

 

 

if (WebUtilities.IsAdmin(User)) {

 

addButton.Visible =

true;

 

 

foreach (GridColumn column in acronymRadGrid.Columns) {

 

column.Visible =

true;

 

}

}

 

//Regular users only get to see the Acronym and Description columns

 

 

else {

 

addButton.Visible =

false;

 

 

foreach (GridColumn column in acronymRadGrid.Columns) {

 

 

if (column.HeaderText != "Acronym" && column.HeaderText != "Description") {

 

column.Visible =

false;

 

}

}

}

Thanks,

-Mike

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Oct 2008, 05:59 PM
Hello Michael,

Please test the following approach:

ItemCreated event handler (C#)
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    GridCommandItem item = e.Item as GridCommandItem; 
    if (item != null
        (item.FindControl("myLinkButton"as LinkButton).Visible = false

ItemCreated event handler (VB)
Protected Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As GridItemEventArgs) 
    Dim item As GridCommandItem = TryCast(e.Item, GridCommandItem) 
    If item <> Nothing Then 
        (TryCast(item.FindControl("myLinkButton"), LinkButton)).Visible = False 
    End If 
End Sub 

<CommandItemTemplate> 
    <asp:LinkButton ID="myLinkButton" runat="server" Text="ClickMe"></asp:LinkButton> 
</CommandItemTemplate> 

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Michael
Top achievements
Rank 1
answered on 30 Oct 2008, 08:25 PM
Daniel,

Thanks for your quick reply. Everything works.

-Mike
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Michael
Top achievements
Rank 1
Share this question
or