Hey!!!
Anyone have any idea that can we fire button click event if the button is added in tabpanel not in panel if have any example or any help would appriciated pls give as soon as possible.

Dani AI

Generated

Common cause and quick checklist: dynamic server controls must be recreated on every postback, with the same server-side ID, and wired to their event handlers before ViewState and postback event handling run (that means in Page_Init / OnInit). If the button is only added on initial load (or added too late), ASP.NET cannot match the posted event to a server control and the Click handler won’t fire. probably hit that lifecycle issue; ’s Tabs sample is useful for static markup but doesn’t show the recreate-on-postback pattern you need.

What to do (practical steps)

  • Save the minimal metadata you need to rebuild tabs/buttons (field id, service name, tab key) in Session or ViewState when you create them.
  • Recreate the TabPanel and its child Button(s) in OnInit/Page_Init on every request, using the same IDs you used originally.
  • Wire the Click (or Command) handler when you recreate the button (don’t put this inside an if(!IsPostBack) block).
  • Use Button.CommandArgument to carry the service name (safer than parsing an ID).

Example pattern (concept, not the code already posted in the thread):

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    var tabs = Session["MyTabs"] as List<TabInfo>;
    if (tabs == null) return;
    foreach (var t in tabs)
    {
        var panel = EnsureTabPanelExists(t.TabKey);          // helper: find or create same-ID panel
        var btn = new Button { ID = "btnRel_" + t.FieldId, CommandArgument = t.ServiceName, Text = "Go" };
        btn.Click += DynamicBtn_Click;
        panel.Controls.Add(btn);
    }
}

protected void DynamicBtn_Click(object sender, EventArgs e)
{
    var service = ((Button)sender).CommandArgument;
    var url = "Customer_List.aspx?Webservice=" + HttpUtility.UrlEncode(service);
    // if inside an AJAX async postback use ScriptManager to redirect; otherwise normal Response.Redirect
}

Troubleshooting tips

  • Put breakpoints in OnInit and in the Click handler to confirm the control is recreated and the handler is attached.
  • Make IDs unique (e.g. include field id) — duplicate IDs stop event-matching.
  • If the page uses UpdatePanel/AJAX, use ScriptManager.RegisterStartupScript to perform client-side redirects on async postbacks, or use Response.Redirect(..., false) plus CompleteRequest.
  • Double-check you’re using the ID property (not a mistyped Id) and that ViewState isn’t accidentally disabled for the container.

Follow that pattern and the Click events on dynamically added buttons inside TabPanel will reliably fire.

Recommended Answers

All 2 Replies

You can find some useful detail on tabpanel at - http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/Tabs/Tabs.aspx

thanks for response but i want Example of dynamically added button on dynamic tab panel and fire click event on buttons click ur url give static information regarding tab panel so pls any other useful information regarding dynamically added button on dynamic tab panel and fire click event on buttons click then pls suggest me. i just clearing my point once again that i have one dynamic added button on tab panel using place holder and i am not able to fire click event on buttons click so i want to know can we do that any example or article is useful regarding this then pls give.

AjaxControlToolkit.TabPanel thePanel = new AjaxControlToolkit.TabPanel();
            thePanel.ID = tabname;
            thePanel.HeaderText = tabname;
            TabContainer1.Controls.Add(thePanel);
PlaceHolder ph1 = new PlaceHolder();
thePanel.Controls.Add(ph1);
string fieldname = serviceHelper.Fields[fieldid].field.ToString();
                   Button b1 = new Button();
                       b1.ID = "b1";
b1.click += new System.EventHandler(this.GetRel_Click);
ph1.Controls.Add(b1);

and this is my click event

protected void GetRel_Click(object sender, EventArgs e)
    {
        string servicename = ((Button)sender).Id.ToString();
        Response.Redirect("Customer_List.aspx?Websevice=" + servicename, false);
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.