Wrong LinkButton Firing Event - Very Odd

Discussion in 'ASP .Net' started by Solomon Shaffer, Jul 29, 2004.

  1. 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 );
    }
    Solomon Shaffer, Jul 29, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JoakimR
    Replies:
    3
    Views:
    3,661
    John Saunders
    Jan 8, 2005
  2. Mantorok

    LinkButton event not firing

    Mantorok, Feb 21, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    507
    Karl Seguin
    Feb 21, 2005
  3. Mel
    Replies:
    6
    Views:
    528
  4. Sunjay Varma
    Replies:
    4
    Views:
    343
    John Roth
    Mar 10, 2011
  5. webdad3

    asp.net linkbutton event not firing

    webdad3, Jul 6, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    191
    Victor Garcia Aprea [MVP]
    Jul 7, 2003
Loading...

Share This Page