Solved

How to fire events(drop down selected index changed) in Dynamically Loaded user controls

Posted on 2010-11-18
8
650 Views
Last Modified: 2012-05-10
i have 3 user controls which are loaded dynamically... can anyone help me how to fire events in a dynamically loaded controls.. none of the events are firing...
any examples.. please
0
Comment
Question by:gautam_reddyc
  • 4
  • 4
8 Comments
 
LVL 11

Expert Comment

by:jasonduan
ID: 34166959
if you want help, post the code that creats the control.
0
 

Author Comment

by:gautam_reddyc
ID: 34167494
jason,
   Here is the code..

UserControl uc = LoadControl("~/User Controls/t/UC1l.ascx") as UserControl;
                                Panel1.Controls.Add(uc);
0
 

Author Comment

by:gautam_reddyc
ID: 34167499
the user control has drop down..
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 11

Expert Comment

by:jasonduan
ID: 34167586
no problem for this piece of code.

Did you test your user control by put it to a page directly (without dynamic loading)?
0
 
LVL 11

Expert Comment

by:jasonduan
ID: 34167591
Make sure you set "AutoPostBack=true" for the dropdown list control.
0
 

Author Comment

by:gautam_reddyc
ID: 34167828
jason,
  Autopostback is true and i load usercontrols dynamically depending on the selected option.
loading to page directly is not an option
0
 

Author Comment

by:gautam_reddyc
ID: 34167831
i have the following sample which loads the User control dynamically..\

UserControl uc = LoadControl("~/User Controls/t/UC1.ascx") as UserControl;
Panel1.Controls.Add(uc);

-- the usercontrol has dropdown and button whose events are not fired..
i tried to add the below code to fire the event using delegate..no luck

private void InitializeComponent()
{
this.ddl.SelectedIndexChanged += new System.EventHandler(ddlBranch_GetEmployee);

this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public event EventHandler BubbleClick;

protected void OnBubbleClick(EventArgs e)
{
if (BubbleClick != null)
{
BubbleClick(this, e);
}
}

0
 
LVL 11

Accepted Solution

by:
jasonduan earned 500 total points
ID: 34168011
I did not ask you load the user control to page directly. I suggest you to test the user control by putting it to page directly. This is part of the diagnostic process to help identify where the problem is. I've been dynamically loading user control in my projects, no problem at all. Just trying to help you to pinpoint the issue.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Service Controller 1 23
asp enable view state 1 24
HTML - Color not displaying correctly in EMAIL. 6 38
MailAddress in vb 4 15
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question