Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Problem with dynamically created nested UpdatePanels

$
0
0

Hi,

I'm having some problems with theese updatepanels.

How should it work: One update panel with an empty tabcontainer.Button clicked calls asyncpostback that first clears tabcontainer tab collection,runs some sql against the backend, creates new tabs depending on the sql result set. In each of the new tabs, there should be a new button that works as a trigger for the new updatepanel inside the same tab. It should then refresh that update panel and create some other controls, gridview and some other.

Problem is: when the new button inside the tab is clicked, it does not fire its own onclick event, but it fires the main button click event, that again refreshes the outer UpdatePanel. Cant refresh the inner one only.

Any ideas

aspx file contains an UpdatePanel, Button and Ajax TabContainer.

<asp:Button ID="btn1" runat="server" Text="Button" OnClick="KlikajBa"/><asp:UpdateProgress runat="server" id="PageUpdateProgress"><ProgressTemplate>
   Loading...</ProgressTemplate></asp:UpdateProgress><asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"><ContentTemplate><asp:TabContainer ID="TabContainer1" runat="server" Height="300" Width="300" BorderColor="Black"
     BorderStyle="Solid" BorderWidth="1px" Font-Names="Arial" Font-Size="10px" BackColor="#CCCCCC"></asp:TabContainer></ContentTemplate><Triggers><asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" /></Triggers></asp:UpdatePanel>

Code behind for button btn1 click event

protected void KlikajBa(object sender, EventArgs e)
        {
            TabContainer1.Tabs.Clear();
            DataTable tableVozilaVozila = GetData("SELECT  blah blah)");

            List<TabPanel> listPanela = new List<TabPanel>();
            foreach (DataRow redVozilo in tableVozilaVozila.Rows)
            {
                TabPanel noviPanel = new TabPanel();
                noviPanel.ID = redVozilo[0].ToString().TrimEnd();
                noviPanel.HeaderText = redVozilo[0].ToString().TrimEnd();

                Button dugme = new Button();
                dugme.Text = "Fetch data list";
                string sta = "btn" + redVozilo[0].ToString().TrimEnd();
                dugme.ID = "btn" + redVozilo[0].ToString().TrimEnd();
                dugme.ClientIDMode = ClientIDMode.Static;
                dugme.Click += new EventHandler(dugme_Click);
                UpdatePanel noviUpdatePanel = new UpdatePanel();
                noviUpdatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;
                noviUpdatePanel.ID = "UpP" + redVozilo[0].ToString().TrimEnd();
                AsyncPostBackTrigger trigger = new AsyncPostBackTrigger(); 
                trigger.ControlID = "btn" + redVozilo[0].ToString().TrimEnd();
                trigger.EventName = "Click";
                noviUpdatePanel.Triggers.Add(trigger);

                noviPanel.Controls.Add(dugme);
                noviPanel.Controls.Add(noviUpdatePanel);
                listPanela.Add(noviPanel);
            }


            foreach (TabPanel tab in listPanela)
            {
                this.TabContainer1.Tabs.Add(tab);
            }
            TabContainer1.ActiveTabIndex = 0;
        }

And  the button dugme click event handler that is never called

protected void dugme_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            this.TextBox1.Text = btn.Text; 
        }




 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>