By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

Wrong LinkButton Firing Event - Very Odd

P: n/a
This is very interesting - and odd. I have a number of LinkButtons
that are created in a custom data grid that I created. The purpose of
the LinkButtons is to provide alphabetical filtering functionality on
the grid. Therefore, a LinkButton is added for every letter of the
alphabet. I also have a numeric filter button and an "All" button that
removes the filter. All of the LinkButtons are wired up to the same
event called AlphaSelector_Click(object sender, System.EventArgs e).
The sender parameter is the object was clicked. In this case, the
LinkButton.

The problem is when I click one of the LinkButtons, it SOMETIMES
passes the wrong LinkButton in the event. This seems to happen only on
a few different letters. For instance, if I click the "A" LinkButton,
it may pass in the "M" LinkButton. If I click the "N" link, it may
think the "Z" LinkButton is clicked.

Like I said, this only happens maybe 20% of the time. The other times,
it works perfectly. I have included code below. Any ideas???

private void WriteAlphaSelector()
{
LinkButton oLinkButton;
LiteralControl oLiteralControl;

for ( int i = 65; i < 91; i++ )
{
char cTemp = (char)i;
oLinkButton = new LinkButton();
oLinkButton.Text = cTemp.ToString();
oLinkButton.CssClass = "datagrid-alphafilter";
oLinkButton.CommandArgument = cTemp.ToString();
oLinkButton.Click += new EventHandler(AlphaSelector_Click);

if ( this.FilterKey == cTemp.ToString() )
{
oLinkButton.Style.Add( "color", "red" );
}
Controls.Add( oLinkButton );
}

oLinkButton = new LinkButton();
oLinkButton.Text = "#";
oLinkButton.CssClass = "datagrid-alphafilter";
oLinkButton.CommandArgument = "Number";
oLinkButton.Click += new EventHandler(AlphaSelector_Click);

if ( this.FilterKey == "Number" )
{
oLinkButton.Style.Add( "color", "red" );
}
Controls.Add( oLinkButton );

oLinkButton = new LinkButton();
oLinkButton.Text = Knowlagent.Common.Util.Resources.GetResourceWord(
"All" );
oLinkButton.CssClass = "datagrid-alphafilter";
oLinkButton.CommandArgument = "";
oLinkButton.Click += new EventHandler(AlphaSelector_Click);
Controls.Add( oLinkButton );
}

private void AlphaSelector_Click( object sender, System.EventArgs e )
{
LinkButton oLinkButton = (LinkButton)sender;
this.FilterKey = oLinkButton.CommandArgument;
this.ChildControlsCreated = false;
OnGridStateChanged( sender, e );
}
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.