473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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 3557
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
0
by: Axel Dahmen | last post by:
Hi, I've created a UserControl containing an <asp:Repeater> control, containing an <asp:Checkbox> control: /------------------------- <asp:Repeater Runat="server" ID="propRpt"> ...
2
by: bill yeager | last post by:
When trying to run my web project, I get the following error: Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the...
0
by: vbMental | last post by:
I'm almost certain this is a bug, or atleast "undesirable behavior". I felt the checkbox list control had shortcomings so I ventured on creating my own checkbox list user control. To put it...
0
by: vbMental | last post by:
I created a user control that, had a datalist with checkboxes inside of the item template. These checkboxes would not retain state. For instance, if I set them to checked inside of the load event...
21
by: Simon Verona | last post by:
Hope somebody can help! I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I've written to a form. Specifically, I'm trying...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
5
by: tshad | last post by:
I get an error when running my Javascript inside my UserControl. It works fine if I put the UserControl Data directly in my Web Page. The stripped down code is: <script language=javascript>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.