Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 180257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:33:16+00:00 2026-05-11T14:33:16+00:00

I created a simple user control using the AJAX Control Toolkit Accordion, LinkButton, and

  • 0

I created a simple user control using the AJAX Control Toolkit Accordion, LinkButton, and TextBox like this:

TestControl.ascx:

<%@ Control Language='C#' AutoEventWireup='true' CodeFile='TestControl.ascx.cs' Inherits='TestControl' %> <%@ Register Assembly='AjaxControlToolkit' Namespace='AjaxControlToolkit' TagPrefix='cc1' %> <cc1:Accordion ID='Accordion1' runat='server'>     <Panes></Panes>     <HeaderTemplate>         <div><%# Container.DataItem %></div>     </HeaderTemplate>     <ContentTemplate>         <div>             <asp:TextBox ID='textBox' Text='<%# Container.DataItem %>' runat='server'></asp:TextBox>             <asp:LinkButton Text='Update' CommandName='Update' CommandArgument='<%# Container.DataItem %>' OnCommand='LinkButton_Command' runat='server'></asp:LinkButton>         </div>     </ContentTemplate> </cc1:Accordion> 

And TestControl.ascx.cx:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;  public partial class TestControl : System.Web.UI.UserControl {     protected void Page_Load(object sender, EventArgs e)     {         Accordion1.DataSource = new string[] { 'one', 'two', 'three' };         Accordion1.DataBind();     }      protected void LinkButton_Command(object sender, CommandEventArgs e)     {         if (e.CommandName == 'Update')         {             TextBox value = ((LinkButton)sender).Parent.FindControl('textBox') as TextBox;             ((string[])Accordion1.DataSource)[Accordion1.SelectedIndex] = value.Text;             Accordion1.DataBind();         }     } } 

The LinkButton_Command event handler doesn’t fire at all on the first click, but on the second. Is there a problem with where the lifecycle the controls are being created that causes events not to be hooked up properly?

Update: I’m adding the control statically:

<%@ Page Language='C#' AutoEventWireup='true'  CodeFile='Default.aspx.cs' Inherits='_Default' %>  <%@ Register src='TestControl.ascx' tagname='TestControl' tagprefix='uc2' %>  <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>  <html xmlns='http://www.w3.org/1999/xhtml'> <head runat='server'>     <title></title> </head> <body>      <form id='form1' runat='server'>         <asp:ScriptManager ID='ScriptManager1' runat='server'>     </asp:ScriptManager>     <div border='1'>         <uc2:TestControl ID='TestControl1' runat='server' />     </div>        </form> </body> </html> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:33:16+00:00Added an answer on May 11, 2026 at 2:33 pm

    Here’s a solution. I checked this out in a test project, and this works:

    ASCX:

    <%@ Control Language='C#' AutoEventWireup='true' CodeBehind='TestControl.ascx.cs' Inherits='WebApplication1.TestControl' %> <%@ Import Namespace='System.ComponentModel'%> <%@ Register Assembly='AjaxControlToolkit' Namespace='AjaxControlToolkit' TagPrefix='cc1' %>  <cc1:Accordion ID='Accordion1' runat='server' Enabled='True'>      <Panes></Panes>     <HeaderTemplate>         <div><asp:Label runat='server' ID='HeaderLabel'><%# Container.DataItem %></asp:Label></div>     </HeaderTemplate>     <ContentTemplate>         <div>             <asp:TextBox ID='textBox' Text='<%# Container.DataItem %>' runat='server'></asp:TextBox>             <asp:LinkButton ID='LinkButton1' Text='Update' CommandName='Update' CommandArgument='<%# Container.DataItem %>'              OnCommand='LinkButton_Command' runat='server'></asp:LinkButton>         </div>     </ContentTemplate>  </cc1:Accordion> 

    Codebehind:

    public partial class TestControl : System.Web.UI.UserControl {     protected void Page_Init(object sender, EventArgs e)     {         if (!IsPostBack)         {             Accordion1.DataSource = new string[] {'one', 'two', 'three'};             Accordion1.DataBind();         }     }      protected void LinkButton_Command(object sender, CommandEventArgs e)     {         if (e.CommandName == 'Update')         {             TextBox value = ((LinkButton)sender).Parent.FindControl('textBox') as TextBox;             (Accordion1.Panes[Accordion1.SelectedIndex].Controls[0].Controls[1] as Label).Text = value.Text;         }     } } 

    It appears that Databinding the Accordion has some issues that mess up your event handlers getting wired up. Re-binding it every time nukes them somehow.

    Also, your posted code has a DataBind() being called in the LinkButton_Command method, which is occurring after viewstate has been loaded. This would lead to the updated data not being shown until the next postback, because the new bindings wouldn’t be saved in ViewState. It would act like it was always one postback behind.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 193k
  • Answers 193k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your approach almost works, you just need to flatten the… May 12, 2026 at 6:36 pm
  • Editorial Team
    Editorial Team added an answer Okay, this is a really bad idea, but it's just… May 12, 2026 at 6:36 pm
  • Editorial Team
    Editorial Team added an answer I would go with your first thought, because it would… May 12, 2026 at 6:36 pm

Related Questions

I'm using mostly jQuery (with asp.net), however I need to create a questionnaire. The
I've created a simple user control which is manually created with something like MyUserControl
I have a Flex application where I'm using a Canvas to contain several other
I'm onto a real head scratcher here ... and it appears to be one

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.