0

I've a question about dynamically loaded controls and events in these controls ( button click in my case :)

Here is what i got one RadPanelBar a Button and hidden input:

              <telerik:RadPanelBar ID="languagesPanelBar" runat="server">
              </telerik:RadPanelBar>
              <asp:Button ID="Button1" runat="server" OnClientClick="funcation(){document.getElementById('someHiddenField').value='true';}" />
              <input id="someHiddenField" type="hidden" runat="server" value="false" />

than on PageLoad event i check if someHiddenField value is true or not, if it's true the new item with dynamically loaded control is added to RadPanelBar :

        void Page_Load(object sender, EventArgs e)
        {
           if(someHiddenField.Value == "true")
             {
                RadPanelItem newRootItem = new RadPanelItem();
                RadPanelItem newChildIteam = new RadPanelItem();
                Control ctrl = LoadControl("testControl.ascx");
                ctrl.ID = "testCtrl";
                newChildItem.Controls.Add(ctrl);
                newRootItem.Items.Add(newChildItem);
                languagesPanelBar.Items.Add(newRootItem);
              }

    }

testControl.ascx have a button in it, but for some reason the onClick event wont fire when control is created dynamically.
Would be glad to hear any suggestion how to solve this problem :)

Thank You in Advance !

shkipper
  • 1,403
  • 3
  • 21
  • 35

1 Answers1

0

Move controls creation code to Page_Init event.

Michał Chaniewski
  • 4,646
  • 1
  • 18
  • 15
  • Hi, Thanks for reply. But if I move creation code to Page_Init i'wont know correct someHiddenField value, it'll be the value from previous postback. – shkipper Jun 22 '09 at 10:29