Event not firing. Adding controls dynamically to UserControl

Discussion in 'ASP .Net Building Controls' started by nitin, Jul 16, 2003.

  1. nitin

    nitin Guest

    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);
    }
    nitin, Jul 16, 2003
    #1
    1. Advertising

  2. 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);
    > }
    >
    >
    Victor Garcia Aprea [MVP], Jul 17, 2003
    #2
    1. Advertising

  3. nitin

    nitin Guest

    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);
    >> }
    >>
    >>

    >
    >
    >.
    >
    nitin, Jul 17, 2003
    #3
  4. 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);
    > >> }
    > >>
    > >>

    > >
    > >
    > >.
    > >
    Victor Garcia Aprea [MVP], Jul 20, 2003
    #4
  5. 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!
    nitin khungar, Jul 21, 2003
    #5
  6. 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!
    Patrick Sullivan, Jul 23, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SevDer
    Replies:
    2
    Views:
    1,301
    Walter Wang [MSFT]
    Nov 13, 2007
  2. nitin khungar

    Event not firing.adding dynamic controls to Usercontrol.

    nitin khungar, Jul 16, 2003, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    203
    nitin
    Jul 21, 2003
  3. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    181
  4. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    187
    vatech1993
    Dec 11, 2004
  5. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    154
Loading...

Share This Page