locked
dynamic imagebutton.click fails after another button on page clicked RRS feed

  • Question

  • User-194673240 posted

     Hello,

    I'm running into a problem using dynamically created imagebuttons. I'm using a dynamically created table to format and display information. as part of each row there are two dynamic imagebuttons, one to edit the row, another to delete the row.

    On the first load the buttons respond to their click events properly, but as soon as I click on one of the linkbuttons outside of the table (read: add new row or cancel) the imagebuttons no longer fire the click event.

    I've verified that a postback is occuring and made sure that the buttons are being re-created in the page_init event but they are still failing to fire.

    Any suggestions? 

    Wednesday, October 15, 2008 11:41 AM

All replies

  • User-797310475 posted

    Is this a site that uses the Dynamic Data framework? Can you provide a simple repro?

    Wednesday, October 15, 2008 2:26 PM
  • User-194673240 posted

     No this site isn't using the Dynamic Data framework.

    Here are samples of the creation of the imagebutton, the event that is supposed to fire when it is clicked, and an event that once is fires the imagebutton no longer works.

    Creation:

    private TableCell GetChangeCell(string IDValue)
        {
            TableCell ChangeCell = new TableCell();
           
            ImageButton ChangeButton = new ImageButton();

            ChangeButton.ID = IDValue + "CHG";
            ChangeButton.AlternateText = "CHG";
            ChangeButton.ImageUrl = "~/images/pencil.png";
            ChangeButton.CssClass = "Icon2";
            ChangeButton.Click += new ImageClickEventHandler(ChangeButtonOnClick);
           
            ChangeCell.ID = IDValue + "CHGCell";

            ChangeCell.Controls.Add(ChangeButton);

            return ChangeCell;

        }

    the event that should fire:

    public void ChangeButtonOnClick(object sender, ImageClickEventArgs e)
        {
            ImageButton ChangeButton = sender as ImageButton;

            string LoadIDValue = ChangeButton.ID.Substring(0, ChangeButton.ID.Length - 3);

            LoadBoardTableAdapter LoadAdapter = new LoadBoardTableAdapter();

            DataTable LoadInfoTable = LoadAdapter.GetByID(new Guid(LoadIDValue));

            AddNewPanel.Visible = true;

           .....Fill in some textboxes here...

            AddNewUpdatePanel.Update();
        } 

    The event that seems to break the imagebutton:

    public void AddNewButtonOnClick(object sender, EventArgs e)
        {
            // reset the field values of the addnew panel
            ResetAddNew();
           
            CustomerDropDown.SelectedIndex = 0;
            WorkFlowDropDown.SelectedIndex = 0;
           
            Page.SetFocus(RefNumBox);

            AddNewPanel.Visible = true;

            AddNewUpdatePanel.Update();
        }

     

    Thanks

    Wednesday, October 15, 2008 2:36 PM
  • User-797310475 posted

    Hi, I can't really immediately see what is wrong. Since this is a forum dedicated to Dynamic Data, you might have more luck asking in the Web Forms forum.

    Wednesday, October 15, 2008 3:10 PM
  • User-194673240 posted

     It's what doesn't make any sense, from looking at it the code should work properly.

    Thanks for the suggestion, that's where I originally tried to post this question but that forum requires moderator approval and this is where whomever it was decided to put my post.

    Wednesday, October 15, 2008 3:29 PM
  • User-194673240 posted

     Well I've sorted out atleast part of the problem. Turns out it was my browser, I've been using Firefox to test my pages. Load it up in IE7 and the events fire properly.

    There's nothing I've seen that should prevent this from working in FF, if anyone has any ideas as to why this wouldn't work please let me know. 

    So much for keeping the site browser independent... 

    Wednesday, October 15, 2008 3:58 PM
  • User1641955678 posted

    This is really the wrong forum for this, so I encourage you to post any follow up to the more general Web Forms forum.

    thanks,
    David

    Wednesday, October 15, 2008 4:27 PM