web controls within user control not firing Init event from C#

web controls within user control not firing Init event from C#

Post by Gal Steinit » Fri, 29 Nov 2002 06:39:35



Either I'm doing something wrong or there is a problem
with asp.net.

I have a user control (.ascx file) that contains a  
System.Web.UI.WebControls.DropDownList control.  In the
codebehind file of the .ascx I am binding a C# function to
the Init even, but it is not firing.

This is the user control's code behind file:

namespace testdotnet3
{

        public abstract class WebUserControl1 :
System.Web.UI.UserControl
        {
                protected
System.Web.UI.WebControls.DropDownList DropDownList1;

                override protected void OnInit(EventArgs e)
                {
                        InitializeComponent();
                        base.OnInit(e);
                }

                private void InitializeComponent()
                {
                        this.DropDownList1.Init += new
System.EventHandler(this.DropDownList1_Init);
                }

                private void DropDownList1_Init(object
sender, System.EventArgs e)
                {
                        Trace.Write("drop down init");
                }
        }

Quote:}

 
 
 

web controls within user control not firing Init event from C#

Post by Marin » Fri, 29 Nov 2002 06:45:16


Will it work if you add the function as an event handler to the dropdown's
Load event instead?


Quote:> Either I'm doing something wrong or there is a problem
> with asp.net.

> I have a user control (.ascx file) that contains a
> System.Web.UI.WebControls.DropDownList control.  In the
> codebehind file of the .ascx I am binding a C# function to
> the Init even, but it is not firing.

> This is the user control's code behind file:

> namespace testdotnet3
> {

> public abstract class WebUserControl1 :
> System.Web.UI.UserControl
> {
> protected
> System.Web.UI.WebControls.DropDownList DropDownList1;

> override protected void OnInit(EventArgs e)
> {
> InitializeComponent();
> base.OnInit(e);
> }

> private void InitializeComponent()
> {
> this.DropDownList1.Init += new
> System.EventHandler(this.DropDownList1_Init);
> }

> private void DropDownList1_Init(object
> sender, System.EventArgs e)
> {
> Trace.Write("drop down init");
> }
> }
> }


 
 
 

web controls within user control not firing Init event from C#

Post by Gal Ori Steini » Mon, 02 Dec 2002 05:19:19


Thanks for the reply -

I just tried it with the "load" event instead of the "init" event, and
it does fire correctly. So does that mean this is a bug in asp.net?


> Will it work if you add the function as an event handler to the dropdown's
> Load event instead?

 
 
 

web controls within user control not firing Init event from C#

Post by Paul Wilson [MVP » Mon, 02 Dec 2002 05:51:46


No, not a bug -- its all a matter of the order of events.
See my other post in this thread for the description.

Thanks, Paul Wilson

 
 
 

web controls within user control not firing Init event from C#

Post by K. Vazir » Mon, 02 Dec 2002 05:44:38


Dear Gal,

    Have you tried calling EnsureChildControls() in your Page.Init before
doing anything with your web controls?

    In Page.Init child controls has not been created yet so you should call
base class Init or call EnsureChildControls(). If you have override OnInit
you can use MyBase.OnInit(e) before anything else in your overrided sub.

    Koorosh Vaziri



> Thanks for the reply -

> I just tried it with the "load" event instead of the "init" event, and
> it does fire correctly. So does that mean this is a bug in asp.net?




Quote:> > Will it work if you add the function as an event handler to the
dropdown's
> > Load event instead?

 
 
 

1. web user control within a web user control

Have web user control that contains four buttons and one a user clicks
a button another web user control is posted to the placeholder.  My
question is after the user enters some data into the textbox and
clicks submit, the child web user control goes away( which i
understand as page_load being called for parent web user control ) and
my database code never gets executed.  I load the child web user
controls dynamically, which is rendered from the use selecting a
particular button.  I have seen several responses to this, but nothing
that as provided answer.  I do understand that the child web user
control is no longer load.

Code:

private void Page_Load(object sender, System.EventArgs e)
{
if( Page.IsPostBack )
{
AddNewProject.Enabled = true;
AddNewComponent.Enabled = true;
DeleteComponent.Enabled = true;
RegisterUsers.Enabled = true;

private void DisplayControl( )
{
try
{
this.plcContent.Controls.Add( Page.LoadControl( "~/Administrators/" +
PageName + ".ascx" ) );
this.ShowSelection( PageName );
catch( Exception )
{
this.plcContent.Controls.Add( new System.Web.UI.LiteralControl(
"Invalid Selection!" ) );

private void ShowSelection( string sPage )
{
Button l_Button = (Button)this.FindControl( sPage );
l_Button.Enabled = false;

private void DeleteComponent_Click(object sender, System.EventArgs e)
{
PageName = "DeleteComponent";
DisplayControl( );

private void AddNewComponent_Click(object sender, System.EventArgs e)
{
PageName = "AddNewComponent";        
DisplayControl( );

private void AddNewProject_Click(object sender, System.EventArgs e)
{
PageName = "AddNewProject";
DisplayControl( );

private void RegisterUsers_Click(object sender, System.EventArgs e)
{
PageName = "RegisterUsers";          
DisplayControl( );

2. Urgently need Philips SJA1000 QTY 200-300

3. Web user controls -- controlling when postback events fire

4. latex2html: equation numbers too far right

5. Event not firing in Web User Control

6. SMS on own webpage??!!!

7. Events not fired for Dynamically re-loaded Web User Controls

8. Is there any ways to map ports, like I was able to do in win98SE, in Win2kPRO??

9. I cannot get a Control's Init Event to fire.

10. Custom control vs User control / Sizing controls within custom control

11. validating event does not fire immediately on user control

12. Click Events on User Control Not Firing First Time They are Clicked.

13. Help with an user control's event not firing