Click here to Skip to main content
16,019,976 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have created user control in Page_init.

It displays on form , i am trying to find it on page load but i am not able to access it.

Here is my code

Page_Init
for (int i = 1; i <= li_Count; i++)
            {
                Movable_Text mt = new Movable_Text();
                mt.ID = "Movable_Text" + Convert.ToString(li_Count);
                mt = LoadControl("~/Controls/Movable_Text.ascx") as Movable_Text;

                DragPanelExtender drag_panel = new DragPanelExtender();
                drag_panel = mt.FindControl("DPE_TextComments") as DragPanelExtender;

                drag_panel.ID = "DPE_TextComments" + Convert.ToString(li_Count);

                this.PH_Master_Page.Controls.Add(mt);
            }

Page_Load
C#
for (int i = 1; i <= li_Count; i++)
        {
            str_drag_panel = "DPE_TextComments" + Convert.ToString(li_Count);
            DragPanelExtender drag_panel = new DragPanelExtender();
            drag_panel = this.FindControl(str_drag_panel) as DragPanelExtender;
            if (drag_panel == null)
            {
                //
            }
            else
            {
                //
            }
        }

where Movable_Text is my user control ,PH_Master_Page is my place holder on master page and li_count is my static variable used to count number of controls added on form.

Please guide me
Posted
Updated 19-Jun-11 23:31pm
v2

Try creating the controls in the PreInit event handler.

ASP.NEt Page Life-cycle reference[^]
 
Share this answer
 
Comments
Alizee@CP 20-Jun-11 8:49am    
Hey john i have created all in preinit. I am using DragExtenderpanel of ajax.

In second case only first control is working and second is not.

What should i do for this
First add user controls to master page check the view source for master page find control id it will displays like ct100_ etc copy drag_panel = this.FindControl("ct00_") as DragPanelExtender;
you will find that control.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900