|
-
May 17th, 2010, 03:57 PM
#12
Re: Disable specific button from set of programatically created buttons?
Sorry this is shooting with a gun to ants
Hum... Parsing through the Controls is somewhat dangerous. You never know what you'll find... What if other LinkButtons are also present in the page ? You'll be shooting at flies with the intent of killing ants !!
I stick to what I said. A simple member variable will do the job with the less amount of code, memory, and processing. And maximum robustness !!
Code:
private LinkButton currentlySelectedLinkLabel;
protected void CreateSetOfLinklabels()
{
// Add label with corresponding page no
for (int i = 1; i < miPages + 1; i++)
{
...
mLbtnPage.ForeColor = your "not selected" color;
...
// Current page
if (Convert.ToInt32(mLbtnPage.ID) == miSelectedPage)
{
SelectLinkLabel(mLbtnPage);
}
}
}
void mLbtnPage_Click(object sender, EventArgs e)
{
SelectLinkLabel(sender as LinkButton);
}
private SelectLinkLabel(LinkButton linkLabel)
{
if (currentlySelectedLinkLabel != null)
{
currentlySelectedLinkLabel.ForeColor = your "not selected" color;
... other processing...
}
currentlySelectedLinkLabel = linkLabel;
if (currentlySelectedLinkLabel != null) // This allows to call this method with null to deselect everything
{
currentlySelectedLinkLabel.ForeColor = your "selected" color;
... other processing...
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|