C
cheloman12
Hi everybody
I’m using user controls in a web application, and i’m triyng to make use of
its init event.
This is the sample code I’m using in the user control
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Controls_MyControlC : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void InitializeComponent()
{
this.Init += new System.EventHandler(this.Controls_MyControlC_Init);
}
private void Controls_MyControlC_Init(object sender, EventArgs e)
{
Session["UserID"] = 2;
}
}
The problem is that neither init nor IntializaComponent events are never
fired when MyControl runs in any page.
But when I do the same in Visual Basic, the event occur so I can use it:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
Session("UserID") = 1
End Sub
What am I missing in the C# version. I’m really disconcerted.
Thank you very much,
Marcelo
I’m using user controls in a web application, and i’m triyng to make use of
its init event.
This is the sample code I’m using in the user control
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Controls_MyControlC : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void InitializeComponent()
{
this.Init += new System.EventHandler(this.Controls_MyControlC_Init);
}
private void Controls_MyControlC_Init(object sender, EventArgs e)
{
Session["UserID"] = 2;
}
}
The problem is that neither init nor IntializaComponent events are never
fired when MyControl runs in any page.
But when I do the same in Visual Basic, the event occur so I can use it:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
Session("UserID") = 1
End Sub
What am I missing in the C# version. I’m really disconcerted.
Thank you very much,
Marcelo