Ask a Question related to ASP.NET Building Controls, Design and Development.
-
nitin #1
Event not firing. Adding controls dynamically to UserControl
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 Guest
-
Adding controls dynamically to a datagrid
Hi, We have a requirement, where based on the UI type selected in a dropdown, a control should get added to the column of a grid dynamically. For... -
Dynamically Adding Controls
I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls... -
Event not firing in usercontrol inside usercontrol
I'm stumped on this problem. I've created a user control that dynamically creates 5 linkbuttons in the CreateChildControls method. Each of these... -
dynamically adding user controls
I have a web form that has a button called "Add Blank Row". Every time this button is pressed a new "blank row" user control should be added to the... -
Event not firing.adding dynamic controls to Usercontrol.
I am adding controls to the UserControl dynamically and then loading the UserControl Dynamically.But I am facing problem with firing of click event... -
Victor Garcia Aprea [MVP] #2
Re: Event not firing. Adding controls dynamically to UserControl
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:
[url]http://obies.com/vga/blog.aspx[/url]
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
"nitin" <nitinsid@rediffmail.com> wrote in message
news:0aba01c34bab$07b52a30$a601280a@phx.gbl...> 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] Guest
-
nitin #3
Re: Event not firing. Adding controls dynamically to UserControl
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
runtime? Or are>-----Original Message-----
>Are you dynamically loading and adding the usercontrol atcontrols not firing>you adding it at design-time? A common problem forlifecycle (ie.>events happens when they're added too late in the controlto the newsgroup>after Load).
>
>--
>Victor Garcia Aprea
>Microsoft MVP | ASP.NET
>Looking for insights on ASP.NET? Read my blog:
>[url]http://obies.com/vga/blog.aspx[/url]
>To contact me remove 'NOSPAM'. Please post all questions(this.SkipReg_Click);>and not by private mail.
>
>"nitin" <nitinsid@rediffmail.com> wrote in message
>news:0aba01c34bab$07b52a30$a601280a@phx.gbl...>> 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>>> }
>>
>>
>>
>> private void SkipRegistration_Click(object sender,
>> System.Web.UI.ImageClickEventArgs e)
>> {
>>
>> string redirectURL = "OrderConfUI.aspx";
>> Response.Redirect(redirectURL, true);
>> }
>>
>>
>
>.
>nitin Guest
-
Victor Garcia Aprea [MVP] #4
Re: Event not firing. Adding controls dynamically to UserControl
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:
[url]http://obies.com/vga/blog.aspx[/url]
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
"nitin" <nitinsid@rediffmail.com> wrote in message
news:08ac01c34c32$00adc5d0$a101280a@phx.gbl...> 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
>> runtime? Or are> >-----Original Message-----
> >Are you dynamically loading and adding the usercontrol at> controls not firing> >you adding it at design-time? A common problem for> lifecycle (ie.> >events happens when they're added too late in the control> to the newsgroup> >after Load).
> >
> >--
> >Victor Garcia Aprea
> >Microsoft MVP | ASP.NET
> >Looking for insights on ASP.NET? Read my blog:
> >[url]http://obies.com/vga/blog.aspx[/url]
> >To contact me remove 'NOSPAM'. Please post all questions> (this.SkipReg_Click);> >and not by private mail.
> >
> >"nitin" <nitinsid@rediffmail.com> wrote in message
> >news:0aba01c34bab$07b52a30$a601280a@phx.gbl...> >> 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> >> >> }
> >>
> >>
> >>
> >> private void SkipRegistration_Click(object sender,
> >> System.Web.UI.ImageClickEventArgs e)
> >> {
> >>
> >> string redirectURL = "OrderConfUI.aspx";
> >> Response.Redirect(redirectURL, true);
> >> }
> >>
> >>
> >
> >.
> >
Victor Garcia Aprea [MVP] Guest
-
nitin khungar #5
Re: Event not firing. Adding controls dynamically to UserControl
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 [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
nitin khungar Guest
-
Patrick Sullivan #6
Re: Event not firing. Adding controls dynamically to UserControl
Can you post what the code looks like now? I'm having a similar problem.
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Patrick Sullivan Guest



Reply With Quote

