Hi All,
I want to generate update panel dynamically.
I am using the following code to do that
UpdatePanel
panel =newUpdatePanel();panel.Mode =
UpdatePanelMode.Conditional;ControlEventTrigger obj =newControlEventTrigger();obj.ControlID =
"Button1";obj.EventName =
"Button1_Click";panel .Triggers.Add(obj);
I want to know how shall we add the controls to the content Template dynamically for the update panel.
Regards,
Techwork
Hello,
myUpdatePanel.Controls.Add( myGridView );
I hope this will work.
Hi,
I had already tried that. It will not work.
We need to add the controls to the content Template of the update panel and not the update panel.
Regards,
Techwork
Hi All,
I am using the following code to do the dynamic update panel.
UpdatePanel panel =newUpdatePanel();
panel.ID =
"panel";panel.Mode =
UpdatePanelMode.Conditional;panel.ContentTemplate = Page.LoadTemplate(
"~/UpdateUserControl.ascx");UpdateUserControl user =new UpdateUserControl();ControlEventTrigger obj =newControlEventTrigger();obj.ControlID =((Button)user.FindControl("Button1")).ID;
panel.Triggers.Add(obj);I am not getting any error but when I run this page the usercontrol is not loading.
I have the scriptamanager in the page. I have written this code in the Page_Load() event of the page
Do I need to do soem more things other than this?
where exactly I am going wrong?
Regards,
Techwork
Firs you have make yourself a UpdatePanelContent class. Make it a inner class within the class holding the updatepanel.
Note, the only method you need to declare in this class, additional to the constructor, is the instantiateIn . Required by the ITemplate interface
publicclassUpdatePanelContent :ITemplate
{publicControl m_Control;
public UpdatePanelContent(Control controlToAdd)
{m_Control = controlToAdd;
}publicvoid InstantiateIn(Control container)
{
container.Controls.Add(m_Control);
}
}
--Now you can instantiate your panelcontent as shown.
Add your hook, page or whatever controlcollection to the panelcontent trough the updatepanelcontent contructor.
UpdatePanelContent panelContent =newUpdatePanelContent(your_control_collection);
the_updatepanel_instance.ContentTemplate = panelContent;
Regards Knut Dullum
No comments:
Post a Comment