-
July 28th, 2010, 04:57 AM
#1
Disable ONE dynamically created linkbutton
I dynamically created a set of linkbuttons which act as page links for my text snippets. On clicking a certain linkbutton the corresponding series of text snippets should be loaded and the selected linkbutton should be disabled. The other linkbuttons should all be enabled. On debugging my code (extract below) the correct page is stored in the variable miSelectedPage but still the false linkbutton is disabled (the last one). Can you see any errors in my code?
Code:
protected void CreateLinkBtns()
{
// Automatically rounded down
miPages = mTextSnippets.Length / 10;
for (int i = 1; i < miPages + 1; i++)
{
// Add label with corresponding page no
mLbtnPage = new LinkButton();
mLbtnPage.ID = i.ToString();
mLbtnPage.Text = i.ToString();
mLbtnPage.Click += new EventHandler(mLbtnPage_Click);
mLbtnPage.Load += new EventHandler(mLbtnPage_Load);
holderPages.Controls.Add(mLbtnPage);
}
}
#endregion
// Selected navi linkbutton
private void mLbtnPage_Click(object sender, EventArgs e)
{
LinkButton lb = sender as LinkButton;
SData.miSelectedBtn = int.Parse(lb.ID);
SelectLinkLabel(sender as LinkButton);
}
// Other navi linkbuttons
private void mLbtnPage_Load(object sender, EventArgs e)
{
LinkButton lb = sender as LinkButton;
SData.miCurrentBtn = int.Parse(lb.ID);
SelectLinkLabel(sender as LinkButton);
}
private void SelectLinkLabel(LinkButton linkLabel)
{
if (mLbtnPage != null)
{
if (linkLabel.ID == Convert.ToString(SData.miSelectedPage))
{
// Selected link label
mLbtnPage.Enabled = false;
}
else
{
// Other link labels
mLbtnPage.Enabled = true;
}
}
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
|