English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In asp.net i have a repeater control which shows some news items. With every item i enclosed an edit and delete link so admins can change the news. But if the userlevel is not adeqate for changing i want the buttons to dissapear. So what i tried to do is simply refer to the button like btnEdit.visible = false. The id of the buttons is btnEdit but it keeps on saying it's not declared. Is it possible that it has something to do with the repater control and id's inside it?

2007-03-07 22:43:43 · 2 answers · asked by rystest 2 in Computers & Internet Programming & Design

2 answers

Yes, you have to remember that the buttons are created at run-time since they are inside the repeaters.

Before I continue, I need to tell you that what you are doing is a poor security practice. Merely hiding the button is not enough. But that's another issue..

Now back to your question. The buttons can be accessed at the repeater_ItemDataBound event. Your code should be something similar to this:






protected void MyRepeater_DataBound(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType. Item) || (e.Item. ItemType == ListItemType. AlternatingItem) )
{
((Button) e.Item. FindControl ("btnTest") ).Visible = false;
}
}

Hope this helps.

2007-03-08 11:06:10 · answer #1 · answered by Smutty 6 · 1 0

In the .aspx file, make sure you have id="btnEdit" runat="server". Sometimes omitting the 'runat' will throw that error

2007-03-08 13:17:48 · answer #2 · answered by rod 6 · 0 0

fedest.com, questions and answers