Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / July 2003

Tip: Looking for answers? Try searching our database.

Event not firing. Adding controls dynamically to UserControl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nitin - 16 Jul 2003 16:00 GMT
I am adding controls to the UserControl dynamically and
then loading the UserControl Dynamically.But I am facing
problem with firing of click event of one of the buttons
within the UserControl.It does not fire.
If I do the same thing in a aspx page instead of a user
control then the event fires perfectly.

Adding of dynamic control in the User control is being
done as follows:

Page_Load
{
///
///
//
Table tbl = new Table();
tbl.Width = Unit.Percentage(100);
this.Controls.Add(tbl);
TableRow tr;
TableCell td;
btnSkipReg.ImageUrl = "../Images/btn_skip_reg.gif";
btnSkipReg.ID = "btnSkipReg";
btnSkipReg.Style.Add("cursor", "hand");
tr = new TableRow();
td = new TableCell();
td.Controls.Add(btnSkipReg);
tr.Cells.Add(td);
tbl.Rows.Add(tr);

///
///

///
}

private void InitializeComponent()
{
this.btnSkipReg.Click += new
System.Web.UI.ImageClickEventHandler(this.SkipReg_Click);
}

private void SkipRegistration_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{

string redirectURL = "OrderConfUI.aspx";
Response.Redirect(redirectURL, true);
}
Victor Garcia Aprea [MVP] - 17 Jul 2003 00:04 GMT
Are you dynamically loading and adding the usercontrol at runtime? Or are
you adding it at design-time? A common problem for controls not firing
events happens when they're added too late in the control lifecycle (ie.
after Load).

Signature

Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.

> I am adding controls to the UserControl dynamically and
> then loading the UserControl Dynamically.But I am facing
[quoted text clipped - 43 lines]
> Response.Redirect(redirectURL, true);
> }
nitin - 17 Jul 2003 08:06 GMT
Hi Victor,

heres the code.

public class RegistrationUI : CompanyName.UI.Page.PageHost
{
protected UCSPGCIRegistration FormControl;

private void Page_Load(object sender, System.EventArgs e)
{
FormControl= (UserControlClassName)LoadControl
("FormControl.ascx");
this.Controls.Add(FormControl);
}
}

Thanks for the help.

Nitin

>-----Original Message-----
>Are you dynamically loading and adding the usercontrol at runtime? Or are
[quoted text clipped - 51 lines]
>
>.
Victor Garcia Aprea [MVP] - 20 Jul 2003 22:36 GMT
Hi Nitin,

Did you solved this?

Try changing the loading code to Init instead of Load and let me know if the
problem still persists,

Signature

Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.

> Hi Victor,
>
[quoted text clipped - 78 lines]
> >
> >.
nitin khungar - 21 Jul 2003 15:18 GMT
Hi,

This got solved.I had to set the usercontrol's ID while loading the user
control, and it worked.

Thanks for the help anyway.

Regards,
Nitin Khungar
Patrick Sullivan - 23 Jul 2003 22:18 GMT
Can you post what the code looks like now? I'm having a similar problem.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.