470,604 Members | 2,293 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

usercontrol and checkbox event

OK, I am trying to fire an event from a usercontrol that tells the page when
a checkbox was clicked.

Here is the control and when I try and wire up the page to catch the event,
my event is not shown. What am I doind wrong?

public delegate void CheckBoxEventHandler(object sender, System.EventArgs e);

public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.CheckBox CheckBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write("WebUserControl1 :: Page_Load <BR>");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.CheckBox1.CheckedChanged += new
System.EventHandler(this.CheckBox1_CheckedChanged) ;
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public event CheckBoxEventHandler CheckedMe;

protected void OnCheckedMe(object sender, System.EventArgs e)
{
if(CheckedMe != null)
{
CheckedMe(this,e);
}
}
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
Response.Write("WebUserControl1 :: Begin CheckBox1_Click <BR>");
OnCheckedMe(this,e);
Response.Write("WebUserControl1 :: End CheckBox1_Click <BR>");
}

Apr 4 '06 #1
5 3452
If you are using ASP.NET 1.1 The page that uses the control has to
1- Register the control, e.g.
<%@ Register TagPrefix="cc" tagName="c1" src="WebUserControl1.ascx" %>

2- declare it in the codebehind as protected, e.g.
protected WebUserControl1 CheckBox1;

Then you will be able to write:
CheckBox1.CheckedMe+=new CheckBoxEventHandler(CheckBox1_CheckedMe);
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"seal" wrote:
OK, I am trying to fire an event from a usercontrol that tells the page when
a checkbox was clicked.

Here is the control and when I try and wire up the page to catch the event,
my event is not shown. What am I doind wrong?

public delegate void CheckBoxEventHandler(object sender, System.EventArgs e);

public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.CheckBox CheckBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write("WebUserControl1 :: Page_Load <BR>");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.CheckBox1.CheckedChanged += new
System.EventHandler(this.CheckBox1_CheckedChanged) ;
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public event CheckBoxEventHandler CheckedMe;

protected void OnCheckedMe(object sender, System.EventArgs e)
{
if(CheckedMe != null)
{
CheckedMe(this,e);
}
}
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
Response.Write("WebUserControl1 :: Begin CheckBox1_Click <BR>");
OnCheckedMe(this,e);
Response.Write("WebUserControl1 :: End CheckBox1_Click <BR>");
}

Apr 4 '06 #2
Phillip thank you for your input.

I think I found the problem and confusion on my part.
I have 1.
<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="Control/WebUserControl1.ascx" %>

<uc1:webusercontrol1 id="WebUserControl11"
runat="server"></uc1:webusercontrol1>

But for your 2nd point I have
protected UserControl WebUserControl11;

I think this is where the problem may be, point 2 that is. By using this I
never see the event CheckedMe. This is a UserControl, so am I declaring it
incorrect on my page?
"Phillip Williams" wrote:
If you are using ASP.NET 1.1 The page that uses the control has to
1- Register the control, e.g.
<%@ Register TagPrefix="cc" tagName="c1" src="WebUserControl1.ascx" %>

2- declare it in the codebehind as protected, e.g.
protected WebUserControl1 CheckBox1;

Then you will be able to write:
CheckBox1.CheckedMe+=new CheckBoxEventHandler(CheckBox1_CheckedMe);
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"seal" wrote:
OK, I am trying to fire an event from a usercontrol that tells the page when
a checkbox was clicked.

Here is the control and when I try and wire up the page to catch the event,
my event is not shown. What am I doind wrong?

public delegate void CheckBoxEventHandler(object sender, System.EventArgs e);

public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.CheckBox CheckBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write("WebUserControl1 :: Page_Load <BR>");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.CheckBox1.CheckedChanged += new
System.EventHandler(this.CheckBox1_CheckedChanged) ;
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public event CheckBoxEventHandler CheckedMe;

protected void OnCheckedMe(object sender, System.EventArgs e)
{
if(CheckedMe != null)
{
CheckedMe(this,e);
}
}
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
Response.Write("WebUserControl1 :: Begin CheckBox1_Click <BR>");
OnCheckedMe(this,e);
Response.Write("WebUserControl1 :: End CheckBox1_Click <BR>");
}

Apr 4 '06 #3
Yes, when you used the base type "UserControl", intellisense could not
display for you the methods in your derived control, which inherited the base
type.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"seal" wrote:
Phillip thank you for your input.

I think I found the problem and confusion on my part.
I have 1.
<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="Control/WebUserControl1.ascx" %>

<uc1:webusercontrol1 id="WebUserControl11"
runat="server"></uc1:webusercontrol1>

But for your 2nd point I have
protected UserControl WebUserControl11;

I think this is where the problem may be, point 2 that is. By using this I
never see the event CheckedMe. This is a UserControl, so am I declaring it
incorrect on my page?
"Phillip Williams" wrote:
If you are using ASP.NET 1.1 The page that uses the control has to
1- Register the control, e.g.
<%@ Register TagPrefix="cc" tagName="c1" src="WebUserControl1.ascx" %>

2- declare it in the codebehind as protected, e.g.
protected WebUserControl1 CheckBox1;

Then you will be able to write:
CheckBox1.CheckedMe+=new CheckBoxEventHandler(CheckBox1_CheckedMe);
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"seal" wrote:
OK, I am trying to fire an event from a usercontrol that tells the page when
a checkbox was clicked.

Here is the control and when I try and wire up the page to catch the event,
my event is not shown. What am I doind wrong?

public delegate void CheckBoxEventHandler(object sender, System.EventArgs e);

public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.CheckBox CheckBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write("WebUserControl1 :: Page_Load <BR>");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.CheckBox1.CheckedChanged += new
System.EventHandler(this.CheckBox1_CheckedChanged) ;
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public event CheckBoxEventHandler CheckedMe;

protected void OnCheckedMe(object sender, System.EventArgs e)
{
if(CheckedMe != null)
{
CheckedMe(this,e);
}
}
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
Response.Write("WebUserControl1 :: Begin CheckBox1_Click <BR>");
OnCheckedMe(this,e);
Response.Write("WebUserControl1 :: End CheckBox1_Click <BR>");
}

Apr 4 '06 #4
Ok, I am not usnderstanding something or I have been looking at it too long.
I have dragged the control on my webform and
I declare the control....
protected UserControl ThisControl;

I try and create an event, though intellesense does not see it. OK, I can
live with that but I would think it would be easier to see the event I am
looking for...
this.ThisControl.CheckedMe += new CheckBoxEventHandler(ThisControl_CheckMe);

Compile error--
does not contain a definition for 'CheckedMe'??

So I can clearly see that there is a definition for the CheckedMe in my
control (public event CheckBoxEventHandler CheckedMe;)

So what am I doing wrong?

"Phillip Williams" wrote:
Yes, when you used the base type "UserControl", intellisense could not
display for you the methods in your derived control, which inherited the base
type.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"seal" wrote:
Phillip thank you for your input.

I think I found the problem and confusion on my part.
I have 1.
<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="Control/WebUserControl1.ascx" %>

<uc1:webusercontrol1 id="WebUserControl11"
runat="server"></uc1:webusercontrol1>

But for your 2nd point I have
protected UserControl WebUserControl11;

I think this is where the problem may be, point 2 that is. By using this I
never see the event CheckedMe. This is a UserControl, so am I declaring it
incorrect on my page?
"Phillip Williams" wrote:
If you are using ASP.NET 1.1 The page that uses the control has to
1- Register the control, e.g.
<%@ Register TagPrefix="cc" tagName="c1" src="WebUserControl1.ascx" %>

2- declare it in the codebehind as protected, e.g.
protected WebUserControl1 CheckBox1;

Then you will be able to write:
CheckBox1.CheckedMe+=new CheckBoxEventHandler(CheckBox1_CheckedMe);
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"seal" wrote:

> OK, I am trying to fire an event from a usercontrol that tells the page when
> a checkbox was clicked.
>
> Here is the control and when I try and wire up the page to catch the event,
> my event is not shown. What am I doind wrong?
>
> public delegate void CheckBoxEventHandler(object sender, System.EventArgs e);
>
> public class WebUserControl1 : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.CheckBox CheckBox1;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> Response.Write("WebUserControl1 :: Page_Load <BR>");
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.CheckBox1.CheckedChanged += new
> System.EventHandler(this.CheckBox1_CheckedChanged) ;
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
> #endregion
>
> public event CheckBoxEventHandler CheckedMe;
>
> protected void OnCheckedMe(object sender, System.EventArgs e)
> {
> if(CheckedMe != null)
> {
> CheckedMe(this,e);
> }
> }
>
>
> private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
> {
> Response.Write("WebUserControl1 :: Begin CheckBox1_Click <BR>");
> OnCheckedMe(this,e);
> Response.Write("WebUserControl1 :: End CheckBox1_Click <BR>");
> }
>
>
>

Apr 4 '06 #5
These are basic concepts in Object Oriented Programming.

An object of type System.Web.UI.UserControl (the base type) does not define
an event named "CheckedMe". Any object even if it were derived from
UserControl but cast as the base type cannot consume that event and hence the
compiler error.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"seal" wrote:
Ok, I am not usnderstanding something or I have been looking at it too long.
I have dragged the control on my webform and
I declare the control....
protected UserControl ThisControl;

I try and create an event, though intellesense does not see it. OK, I can
live with that but I would think it would be easier to see the event I am
looking for...
this.ThisControl.CheckedMe += new CheckBoxEventHandler(ThisControl_CheckMe);

Compile error--
does not contain a definition for 'CheckedMe'??

So I can clearly see that there is a definition for the CheckedMe in my
control (public event CheckBoxEventHandler CheckedMe;)

So what am I doing wrong?

"Phillip Williams" wrote:
Yes, when you used the base type "UserControl", intellisense could not
display for you the methods in your derived control, which inherited the base
type.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"seal" wrote:
Phillip thank you for your input.

I think I found the problem and confusion on my part.
I have 1.
<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="Control/WebUserControl1.ascx" %>

<uc1:webusercontrol1 id="WebUserControl11"
runat="server"></uc1:webusercontrol1>

But for your 2nd point I have
protected UserControl WebUserControl11;

I think this is where the problem may be, point 2 that is. By using this I
never see the event CheckedMe. This is a UserControl, so am I declaring it
incorrect on my page?
"Phillip Williams" wrote:

> If you are using ASP.NET 1.1 The page that uses the control has to
> 1- Register the control, e.g.
> <%@ Register TagPrefix="cc" tagName="c1" src="WebUserControl1.ascx" %>
>
> 2- declare it in the codebehind as protected, e.g.
> protected WebUserControl1 CheckBox1;
>
> Then you will be able to write:
> CheckBox1.CheckedMe+=new CheckBoxEventHandler(CheckBox1_CheckedMe);
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "seal" wrote:
>
> > OK, I am trying to fire an event from a usercontrol that tells the page when
> > a checkbox was clicked.
> >
> > Here is the control and when I try and wire up the page to catch the event,
> > my event is not shown. What am I doind wrong?
> >
> > public delegate void CheckBoxEventHandler(object sender, System.EventArgs e);
> >
> > public class WebUserControl1 : System.Web.UI.UserControl
> > {
> > protected System.Web.UI.WebControls.CheckBox CheckBox1;
> >
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > // Put user code to initialize the page here
> > Response.Write("WebUserControl1 :: Page_Load <BR>");
> > }
> >
> > #region Web Form Designer generated code
> > override protected void OnInit(EventArgs e)
> > {
> > //
> > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> > //
> > InitializeComponent();
> > base.OnInit(e);
> > }
> >
> > /// <summary>
> > /// Required method for Designer support - do not modify
> > /// the contents of this method with the code editor.
> > /// </summary>
> > private void InitializeComponent()
> > {
> > this.CheckBox1.CheckedChanged += new
> > System.EventHandler(this.CheckBox1_CheckedChanged) ;
> > this.Load += new System.EventHandler(this.Page_Load);
> >
> > }
> > #endregion
> >
> > public event CheckBoxEventHandler CheckedMe;
> >
> > protected void OnCheckedMe(object sender, System.EventArgs e)
> > {
> > if(CheckedMe != null)
> > {
> > CheckedMe(this,e);
> > }
> > }
> >
> >
> > private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
> > {
> > Response.Write("WebUserControl1 :: Begin CheckBox1_Click <BR>");
> > OnCheckedMe(this,e);
> > Response.Write("WebUserControl1 :: End CheckBox1_Click <BR>");
> > }
> >
> >
> >

Apr 4 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Axel Dahmen | last post: by
2 posts views Thread by bill yeager | last post: by
9 posts views Thread by Marcelo Cabrera | last post: by
5 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.