0

We have created a UserControl. Inside user control we are creating an update panel. Inside the panel we are creating various controls such as TextBox, Button, DropDownList and ListBox and event associated with them buttonclick(),DropDown_selectedIndexChanged(),TextBox_TextChenged() etc. All the controls(including update panel) are created programatically using c#. To ajaxify the events we have used ScriptManager.

ScriptManager is added on OnInit function programatically like as shown:

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
            if (scriptManager == null)
            {
                scriptManager = new ScriptManager();
                //scriptManager.EnablePartialRendering = true;
                this.Controls.AddAt(0,scriptManager);
            }

Every time after page load only one event get fired partial postback(which is desired) but after that no event gets fired .

All valid changes have already been done in web.config file for AJAX . Please suggest the possible cause and solution of the problem.

Anoop
  • 5,246
  • 6
  • 27
  • 29

1 Answers1

0

On a partial postback, the ScriptManager will not be added because you are trying to add it outside the UpdatePanel (where it has to be). This works on the first page load because it's not a partial postback. But after the partial postback, the dynamically added ScriptManager won't be available to the page, and because you are trying to add it outside the UpdatePanel -- AddAt(0,...) - after a partial postback, it won't actually be added. On a partial postback you can only affect things inside the UpdatePanel that initiated the postback.

Bottom line is, you really can't add a ScriptManager dynamically, since it will never be there after a partial postback. Just like you can't dynamically add any other control outside of an UpdatePanel after an event sourced inside it.

Jamie Treworgy
  • 23,934
  • 8
  • 76
  • 119
  • but the same application is working perfectly on another server with same configuration. – Anoop Dec 14 '10 at 14:23
  • Intuitively, I would think that all the scripts generated by the initial page load would not link correctly with whatever script is generated inside the UpdatePanel after a partial postback, because it's being generated by a different instance of the ScriptManager. I could be wrong, though, maybe ScriptManager it is not context-dependent, but it seems very counter intuitive that this design would work. Anyway if it works on another server with exactly the same configuration... then I'd say the configurations probably aren't exactly the same. – Jamie Treworgy Dec 14 '10 at 15:00
  • Did you see this thread? A variety of ways this could work. http://stackoverflow.com/questions/183950/add-scriptmanager-to-page-programmatically – Jamie Treworgy Dec 14 '10 at 15:09