Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Event not firing. Adding controls dynamically to UserControl

Reply
Thread Tools

Event not firing. Adding controls dynamically to UserControl

 
 
nitin
Guest
Posts: n/a
 
      07-16-2003
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);
}


 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      07-16-2003
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).

--
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.

"nitin" <> wrote in message
news:0aba01c34bab$07b52a30$...
> 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);
> }
>
>



 
Reply With Quote
 
 
 
 
nitin
Guest
Posts: n/a
 
      07-17-2003
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
>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).
>
>--
>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.
>
>"nitin" <> wrote in message
>news:0aba01c34bab$07b52a30$...
>> 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);
>> }
>>
>>

>
>
>.
>

 
Reply With Quote
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      07-20-2003
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,

--
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.

"nitin" <> wrote in message
news:08ac01c34c32$00adc5d0$...
> 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
> >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).
> >
> >--
> >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.
> >
> >"nitin" <> wrote in message
> >news:0aba01c34bab$07b52a30$...
> >> 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);
> >> }
> >>
> >>

> >
> >
> >.
> >



 
Reply With Quote
 
nitin khungar
Guest
Posts: n/a
 
      07-21-2003
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



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Patrick Sullivan
Guest
Posts: n/a
 
      07-23-2003
Can you post what the code looks like now? I'm having a similar problem.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 1 12-11-2004 01:28 PM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 0 12-10-2004 02:21 PM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 0 12-10-2004 02:20 PM
Dynamically adding controls at runtime - event problem Uzi Baruch ASP .Net 0 12-17-2003 10:05 AM
Event not firing.adding dynamic controls to Usercontrol. nitin khungar ASP .Net Building Controls 3 07-21-2003 02:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57