473,785 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CheckBoxEventHa ndler(object sender, System.EventArg s e);

public class WebUserControl1 : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Chec kBox CheckBox1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
Response.Write( "WebUserControl 1 :: Page_Load <BR>");
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.CheckBox1. CheckedChanged += new
System.EventHan dler(this.Check Box1_CheckedCha nged);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

public event CheckBoxEventHa ndler CheckedMe;

protected void OnCheckedMe(obj ect sender, System.EventArg s e)
{
if(CheckedMe != null)
{
CheckedMe(this, e);
}
}
private void CheckBox1_Check edChanged(objec t sender, System.EventArg s e)
{
Response.Write( "WebUserControl 1 :: Begin CheckBox1_Click <BR>");
OnCheckedMe(thi s,e);
Response.Write( "WebUserControl 1 :: End CheckBox1_Click <BR>");
}

Apr 4 '06 #1
5 3580
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="WebUserCon trol1.ascx" %>

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

Then you will be able to write:
CheckBox1.Check edMe+=new CheckBoxEventHa ndler(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 CheckBoxEventHa ndler(object sender, System.EventArg s e);

public class WebUserControl1 : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Chec kBox CheckBox1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
Response.Write( "WebUserControl 1 :: Page_Load <BR>");
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.CheckBox1. CheckedChanged += new
System.EventHan dler(this.Check Box1_CheckedCha nged);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

public event CheckBoxEventHa ndler CheckedMe;

protected void OnCheckedMe(obj ect sender, System.EventArg s e)
{
if(CheckedMe != null)
{
CheckedMe(this, e);
}
}
private void CheckBox1_Check edChanged(objec t sender, System.EventArg s e)
{
Response.Write( "WebUserControl 1 :: Begin CheckBox1_Click <BR>");
OnCheckedMe(thi s,e);
Response.Write( "WebUserControl 1 :: 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="WebUse rControl1"
Src="Control/WebUserControl1 .ascx" %>

<uc1:webusercon trol1 id="WebUserCont rol11"
runat="server"> </uc1:webusercont rol1>

But for your 2nd point I have
protected UserControl WebUserControl1 1;

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="WebUserCon trol1.ascx" %>

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

Then you will be able to write:
CheckBox1.Check edMe+=new CheckBoxEventHa ndler(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 CheckBoxEventHa ndler(object sender, System.EventArg s e);

public class WebUserControl1 : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Chec kBox CheckBox1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
Response.Write( "WebUserControl 1 :: Page_Load <BR>");
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.CheckBox1. CheckedChanged += new
System.EventHan dler(this.Check Box1_CheckedCha nged);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

public event CheckBoxEventHa ndler CheckedMe;

protected void OnCheckedMe(obj ect sender, System.EventArg s e)
{
if(CheckedMe != null)
{
CheckedMe(this, e);
}
}
private void CheckBox1_Check edChanged(objec t sender, System.EventArg s e)
{
Response.Write( "WebUserControl 1 :: Begin CheckBox1_Click <BR>");
OnCheckedMe(thi s,e);
Response.Write( "WebUserControl 1 :: End CheckBox1_Click <BR>");
}

Apr 4 '06 #3
Yes, when you used the base type "UserContro l", 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="WebUse rControl1"
Src="Control/WebUserControl1 .ascx" %>

<uc1:webusercon trol1 id="WebUserCont rol11"
runat="server"> </uc1:webusercont rol1>

But for your 2nd point I have
protected UserControl WebUserControl1 1;

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="WebUserCon trol1.ascx" %>

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

Then you will be able to write:
CheckBox1.Check edMe+=new CheckBoxEventHa ndler(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 CheckBoxEventHa ndler(object sender, System.EventArg s e);

public class WebUserControl1 : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Chec kBox CheckBox1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
Response.Write( "WebUserControl 1 :: Page_Load <BR>");
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.CheckBox1. CheckedChanged += new
System.EventHan dler(this.Check Box1_CheckedCha nged);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

public event CheckBoxEventHa ndler CheckedMe;

protected void OnCheckedMe(obj ect sender, System.EventArg s e)
{
if(CheckedMe != null)
{
CheckedMe(this, e);
}
}
private void CheckBox1_Check edChanged(objec t sender, System.EventArg s e)
{
Response.Write( "WebUserControl 1 :: Begin CheckBox1_Click <BR>");
OnCheckedMe(thi s,e);
Response.Write( "WebUserControl 1 :: 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.ThisContro l.CheckedMe += new CheckBoxEventHa ndler(ThisContr ol_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 CheckBoxEventHa ndler CheckedMe;)

So what am I doing wrong?

"Phillip Williams" wrote:
Yes, when you used the base type "UserContro l", 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="WebUse rControl1"
Src="Control/WebUserControl1 .ascx" %>

<uc1:webusercon trol1 id="WebUserCont rol11"
runat="server"> </uc1:webusercont rol1>

But for your 2nd point I have
protected UserControl WebUserControl1 1;

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="WebUserCon trol1.ascx" %>

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

Then you will be able to write:
CheckBox1.Check edMe+=new CheckBoxEventHa ndler(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 CheckBoxEventHa ndler(object sender, System.EventArg s e);
>
> public class WebUserControl1 : System.Web.UI.U serControl
> {
> protected System.Web.UI.W ebControls.Chec kBox CheckBox1;
>
> private void Page_Load(objec t sender, System.EventArg s e)
> {
> // Put user code to initialize the page here
> Response.Write( "WebUserControl 1 :: Page_Load <BR>");
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArg s e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeCompo nent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeCompo nent()
> {
> this.CheckBox1. CheckedChanged += new
> System.EventHan dler(this.Check Box1_CheckedCha nged);
> this.Load += new System.EventHan dler(this.Page_ Load);
>
> }
> #endregion
>
> public event CheckBoxEventHa ndler CheckedMe;
>
> protected void OnCheckedMe(obj ect sender, System.EventArg s e)
> {
> if(CheckedMe != null)
> {
> CheckedMe(this, e);
> }
> }
>
>
> private void CheckBox1_Check edChanged(objec t sender, System.EventArg s e)
> {
> Response.Write( "WebUserControl 1 :: Begin CheckBox1_Click <BR>");
> OnCheckedMe(thi s,e);
> Response.Write( "WebUserControl 1 :: End CheckBox1_Click <BR>");
> }
>
>
>

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

An object of type System.Web.UI.U serControl (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.ThisContro l.CheckedMe += new CheckBoxEventHa ndler(ThisContr ol_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 CheckBoxEventHa ndler CheckedMe;)

So what am I doing wrong?

"Phillip Williams" wrote:
Yes, when you used the base type "UserContro l", 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="WebUse rControl1"
Src="Control/WebUserControl1 .ascx" %>

<uc1:webusercon trol1 id="WebUserCont rol11"
runat="server"> </uc1:webusercont rol1>

But for your 2nd point I have
protected UserControl WebUserControl1 1;

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="WebUserCon trol1.ascx" %>
>
> 2- declare it in the codebehind as protected, e.g.
> protected WebUserControl1 CheckBox1;
>
> Then you will be able to write:
> CheckBox1.Check edMe+=new CheckBoxEventHa ndler(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 CheckBoxEventHa ndler(object sender, System.EventArg s e);
> >
> > public class WebUserControl1 : System.Web.UI.U serControl
> > {
> > protected System.Web.UI.W ebControls.Chec kBox CheckBox1;
> >
> > private void Page_Load(objec t sender, System.EventArg s e)
> > {
> > // Put user code to initialize the page here
> > Response.Write( "WebUserControl 1 :: Page_Load <BR>");
> > }
> >
> > #region Web Form Designer generated code
> > override protected void OnInit(EventArg s e)
> > {
> > //
> > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> > //
> > InitializeCompo nent();
> > base.OnInit(e);
> > }
> >
> > /// <summary>
> > /// Required method for Designer support - do not modify
> > /// the contents of this method with the code editor.
> > /// </summary>
> > private void InitializeCompo nent()
> > {
> > this.CheckBox1. CheckedChanged += new
> > System.EventHan dler(this.Check Box1_CheckedCha nged);
> > this.Load += new System.EventHan dler(this.Page_ Load);
> >
> > }
> > #endregion
> >
> > public event CheckBoxEventHa ndler CheckedMe;
> >
> > protected void OnCheckedMe(obj ect sender, System.EventArg s e)
> > {
> > if(CheckedMe != null)
> > {
> > CheckedMe(this, e);
> > }
> > }
> >
> >
> > private void CheckBox1_Check edChanged(objec t sender, System.EventArg s e)
> > {
> > Response.Write( "WebUserControl 1 :: Begin CheckBox1_Click <BR>");
> > OnCheckedMe(thi s,e);
> > Response.Write( "WebUserControl 1 :: 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
4027
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 same way a menu does. To do this my control needs to get notified when the user tried to click off of it. The Leave and LostFocus events of the UserControl work most of the time but not always. For example, if they click on a part of the form...
0
1842
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"> <ItemTemplate> <tr><td> <asp:CheckBox Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Description")%>' TextAlign="Right"/> <asp:Literal Runat="server" Visible="False" Text='<%#DataBinder.Eval(Container.DataItem,"ID")%>'/>
2
2670
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 following specific parse error details and modify your source file appropriately. Parser Error Message: The base class includes the
0
1407
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 shortly, the usercontrol had a checkbox list inside of it, that would be bound by a datasource that was to be specified as a property of the control. It also had an all checkbox at the top that would select all of the checkboxes in the list... The...
0
1118
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 of the UserControl, they would appear false(the default value) when inside the top level datagrid. Here's the walkthrough (tried to make it as quick as possible): Start a new ASP.NET Web Application project. 1. Create a usercontrol....
21
1902
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 to data bind to a normal class. So I've extended the standard text box to include a field for object name and property name. I want to be able to add a line such as : controlname.DataBindings.Add("Text", objectName, "myPropertyName") I've...
41
4328
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 on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
9
14459
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 does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same time. I have to click twice on the controls for the events to be raised, the first time nothing...
5
3690
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> function CheckQuestion() { var checkBox = document.getElementById('SecurityStandard'); alert("checkBox.checked = " + checkBox.checked);
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9956
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.