473,396 Members | 2,081 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,396 software developers and data experts.

Public delegate & event not seen in parent instantiation

I have a partial class of a UserControl coded as follows:

public partial class Login : System.Windows.Controls.UserControl
{
public delegate void StartingLoginHandler(string message);
public event StartingLoginHandler StartingLogin;

public Login()
{
InitializeComponent();
}

protected void OnStartingLogin(string message)
{
if (StartingLogin != null)
{
StartingLogin(message);
}
}
}

When I instantiate a UserControl Login() object in the parent page.xaml.cs I
cannot see the event to attach to it. It won't give any Intellisense on the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won't compile; compiler just reports StartingLogin doesn't exist.

What is the solution or a work-around please?
--
Mike McAllister
Mar 30 '07 #1
10 1373
Hi,

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:95**********************************@microsof t.com...
When I instantiate a UserControl Login() object in the parent page.xaml.cs
I
cannot see the event to attach to it. It won't give any Intellisense on
the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won't compile; compiler just reports StartingLogin doesn't exist.

What is the solution or a work-around please?
Of course it cannot be seen, as it's not defined in UserControl.

This is what you should do:

Login l = yourControl as Login;
if ( l != null )
l.StartingLogin += oLogin.StartingLoginHandler(delegate_method);
else
throw new Exception( "Incorrect control type");
Mar 30 '07 #2
l.StartingLogin now shows in Intellisense. However, both the following two
lines throw compiler errors:

l.StartingLogin +=
oLogin.StartingLoginHandler(delegate_method);
l.StartingLogin += l.StartingLoginHandler(delegate_method);

'System.Windows.Controls.UserControl' does not contain a definition for
'StartingLoginHandler'

Do you have any suggestions for a work-around, please?
--
Mike McAllister
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:95**********************************@microsof t.com...
When I instantiate a UserControl Login() object in the parent page.xaml.cs
I
cannot see the event to attach to it. It won't give any Intellisense on
the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won't compile; compiler just reports StartingLogin doesn't exist.

What is the solution or a work-around please?

Of course it cannot be seen, as it's not defined in UserControl.

This is what you should do:

Login l = yourControl as Login;
if ( l != null )
l.StartingLogin += oLogin.StartingLoginHandler(delegate_method);
else
throw new Exception( "Incorrect control type");
Mar 31 '07 #3

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:C6**********************************@microsof t.com...
l.StartingLogin now shows in Intellisense. However, both the following two
lines throw compiler errors:

l.StartingLogin +=
oLogin.StartingLoginHandler(delegate_method);
l.StartingLogin += l.StartingLoginHandler(delegate_method);

'System.Windows.Controls.UserControl' does not contain a definition for
'StartingLoginHandler'

Do you have any suggestions for a work-around, please?
Change the type of the variable from UserControl to the exact derived type,
to be able to use your additional methods/events/properties.
--
Mike McAllister
"Ignacio Machin ( .NET/ C# MVP )" wrote:
>Hi,

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:95**********************************@microso ft.com...
When I instantiate a UserControl Login() object in the parent
page.xaml.cs
I
cannot see the event to attach to it. It won't give any Intellisense on
the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won't compile; compiler just reports StartingLogin doesn't exist.

What is the solution or a work-around please?

Of course it cannot be seen, as it's not defined in UserControl.

This is what you should do:

Login l = yourControl as Login;
if ( l != null )
l.StartingLogin += oLogin.StartingLoginHandler(delegate_method);
else
throw new Exception( "Incorrect control type");

Mar 31 '07 #4
Here is a solution that works I found by trial and error:

oLogin = new Login(ref oAgilityService1, ref
dsSessionCustomersAndPV);
//Workaround from Microsoft Managed Newsgroups...
Login l = oLogin as Login;
if (l != null)
{
l.StartingLogin += new Login.StartingLoginHandler(StartLogin);
l.EndingLogin += new Login.EndingLoginHandler(EndLogin);
l.LoginMessage += new Login.LoginMessageHandler(LoginMessage);
}
else
{
throw new Exception("Incorrect control type");
}

--
Mike McAllister
"Ben Voigt" wrote:
>
"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:C6**********************************@microsof t.com...
l.StartingLogin now shows in Intellisense. However, both the following two
lines throw compiler errors:

l.StartingLogin +=
oLogin.StartingLoginHandler(delegate_method);
l.StartingLogin += l.StartingLoginHandler(delegate_method);

'System.Windows.Controls.UserControl' does not contain a definition for
'StartingLoginHandler'

Do you have any suggestions for a work-around, please?

Change the type of the variable from UserControl to the exact derived type,
to be able to use your additional methods/events/properties.
--
Mike McAllister
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

"Mike McAllister" <mi************@newsgroup.nospamwrote in message
news:95**********************************@microsof t.com...

When I instantiate a UserControl Login() object in the parent
page.xaml.cs
I
cannot see the event to attach to it. It won't give any Intellisense on
the
event and if I just go ahead and type it in like:

oLogin.StartingLogin += oLogin.StartingLoginHandler(delegate_method);

it won't compile; compiler just reports StartingLogin doesn't exist.

What is the solution or a work-around please?

Of course it cannot be seen, as it's not defined in UserControl.

This is what you should do:

Login l = yourControl as Login;
if ( l != null )
l.StartingLogin += oLogin.StartingLoginHandler(delegate_method);
else
throw new Exception( "Incorrect control type");


Mar 31 '07 #5
Mike McAllister <mi************@newsgroup.nospamwrote:
Here is a solution that works I found by trial and error:

oLogin = new Login(ref oAgilityService1, ref
dsSessionCustomersAndPV);
//Workaround from Microsoft Managed Newsgroups...
Login l = oLogin as Login;
if (l != null)
{
l.StartingLogin += new Login.StartingLoginHandler(StartLogin);
l.EndingLogin += new Login.EndingLoginHandler(EndLogin);
l.LoginMessage += new Login.LoginMessageHandler(LoginMessage);
}
else
{
throw new Exception("Incorrect control type");
}
One style hint - if you're going to throw an exception if something
isn't the right type, just cast it. That will give a more specific
exception, and avoid cluttering up your code. The above becomes just:

oLogin = new Login(ref oAgilityService1,
ref dsSessionCustomersAndPV);

//Workaround from Microsoft Managed Newsgroups...
Login l = (Login) oLogin;
l.StartingLogin += new Login.StartingLoginHandler(StartLogin);
l.EndingLogin += new Login.EndingLoginHandler(EndLogin);
l.LoginMessage += new Login.LoginMessageHandler(LoginMessage);

Of course, in this case there's no risk anyway, because oLogin is
clearly a Login given the call to the constructor.

Are you sure you really need to pass those Login parameters by
reference, by the way?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 1 '07 #6
Great suggestion on the casting! Thanks.

I think I need to pass them by ref; but I'm always learning...

Here's my scenario:

Login is short-lived. It's a XAML UserControl that logs into a web service
SOA. The DataSet by ref stores all the application state information from the
login.

I'm passing the web service by ref because it will be used for many other
calls elsewhere in the applicationI'm just starting.

I know this is a bit off-topic, but the application I'm just now starting
will eventually be 1,300+ screens and will be an .xbap application of a full
ERP system.

What we're designing is a type of MDI where UserControls will be
instantiated at runtime. A Manager for those UserControls will live at the
root level for the duration of the application.

I very much appreciate your comments and suggestions as I want to make sure
I have and excellent ground-level architecture for this 'very large' project.

Any suggestions are welcome.
--
Mike McAllister
"Jon Skeet [C# MVP]" wrote:
Mike McAllister <mi************@newsgroup.nospamwrote:
Here is a solution that works I found by trial and error:

oLogin = new Login(ref oAgilityService1, ref
dsSessionCustomersAndPV);
//Workaround from Microsoft Managed Newsgroups...
Login l = oLogin as Login;
if (l != null)
{
l.StartingLogin += new Login.StartingLoginHandler(StartLogin);
l.EndingLogin += new Login.EndingLoginHandler(EndLogin);
l.LoginMessage += new Login.LoginMessageHandler(LoginMessage);
}
else
{
throw new Exception("Incorrect control type");
}

One style hint - if you're going to throw an exception if something
isn't the right type, just cast it. That will give a more specific
exception, and avoid cluttering up your code. The above becomes just:

oLogin = new Login(ref oAgilityService1,
ref dsSessionCustomersAndPV);

//Workaround from Microsoft Managed Newsgroups...
Login l = (Login) oLogin;
l.StartingLogin += new Login.StartingLoginHandler(StartLogin);
l.EndingLogin += new Login.EndingLoginHandler(EndLogin);
l.LoginMessage += new Login.LoginMessageHandler(LoginMessage);

Of course, in this case there's no risk anyway, because oLogin is
clearly a Login given the call to the constructor.

Are you sure you really need to pass those Login parameters by
reference, by the way?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 1 '07 #7
Mike McAllister <mi************@newsgroup.nospamwrote:
Great suggestion on the casting! Thanks.

I think I need to pass them by ref; but I'm always learning...

Here's my scenario:

Login is short-lived. It's a XAML UserControl that logs into a web service
SOA. The DataSet by ref stores all the application state information from the
login.

I'm passing the web service by ref because it will be used for many other
calls elsewhere in the applicationI'm just starting.
I suspect you don't really understand what passing by reference means
then.

See http://pobox.com/~skeet/csharp/parameters.html for a fairly
thorough description.
I know this is a bit off-topic, but the application I'm just now starting
will eventually be 1,300+ screens and will be an .xbap application of a full
ERP system.
In that case it's definitely worth making sure you understand pass by
reference vs pass by value (and value types vs reference types) before
making all of those screens :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 1 '07 #8
Hi Mike,

There're two kinds of types in .NET world, i.e. value type and reference
type.

A value-type variable contains its data directly as opposed to a
reference-type variable, which contains a reference to its data. Therefore,
passing a value-type variable to a method means passing a copy of the
variable to the method. Any changes to the parameter that take place inside
the method have no effect on the original data stored in the variable.

If you want the called method to change the value of the parameter, you
have to pass it by reference, using the ref or out keyword.

A variable of a reference type does not contain its data directly; it
contains a reference to its data. When you pass a reference-type parameter
by value, it is possible to change the data pointed to by the reference,
such as the value of a class member. However, you cannot change the value
of the reference itself; that is, you cannot use the same reference to
allocate memory for a new class and have it persist outside the block. To
do that, pass the parameter using the ref or out keyword.

In your practice, both the DataSet and WebService types are of reference
type. If you don't intend to change the values of the reference themselves,
you needn't use the ref keyword.

In addition, you may place the DataSet and WebService objects at the root
level for the duration of the application, to enable them to be used for
many other calls in the application.

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 2 '07 #9
Linda, Thank you.

Your very excellent description matches my understanding and coding
practices. Thanks for taking the time to make sure I understand. You have
gone 'above and beyond' which I appreciate very much.

Thanks,
--
Mike McAllister
"Linda Liu [MSFT]" wrote:
Hi Mike,

There're two kinds of types in .NET world, i.e. value type and reference
type.

A value-type variable contains its data directly as opposed to a
reference-type variable, which contains a reference to its data. Therefore,
passing a value-type variable to a method means passing a copy of the
variable to the method. Any changes to the parameter that take place inside
the method have no effect on the original data stored in the variable.

If you want the called method to change the value of the parameter, you
have to pass it by reference, using the ref or out keyword.

A variable of a reference type does not contain its data directly; it
contains a reference to its data. When you pass a reference-type parameter
by value, it is possible to change the data pointed to by the reference,
such as the value of a class member. However, you cannot change the value
of the reference itself; that is, you cannot use the same reference to
allocate memory for a new class and have it persist outside the block. To
do that, pass the parameter using the ref or out keyword.

In your practice, both the DataSet and WebService types are of reference
type. If you don't intend to change the values of the reference themselves,
you needn't use the ref keyword.

In addition, you may place the DataSet and WebService objects at the root
level for the duration of the application, to enable them to be used for
many other calls in the application.

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 2 '07 #10
Have you misspelt the user control's namespace name?

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Apr 3 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
5
by: Rene | last post by:
I created a class (SomeClass), on that class, I declared a delegate (OnXyz) and then declared an event based on that delegate (Xyz). All this in the same class. After that, I created another class...
7
by: Brian Keating | last post by:
hi there this may seem like a silly question but what exactly is the difference ... ok .. that question is probably a bit ambiguous.. i know what delegates are i know what events are, i use them...
3
by: George K | last post by:
Hi, i have a very irriting problem that i have written a short piece of code to demonstrate. The problem is that my aspx page is not fully refreshed after an event, which is delegated to an...
2
by: Mike | last post by:
Greetings, It would seem that this topic has been discussed at some length, but I was unable to discern whether there was a clear cut solution to resolve and/or otherwise workaround the issue. ...
6
by: Bart Burkhardt | last post by:
Hi, I could use some help in setting a C# callback function that an external unmanaged dll will call on a event. Using a delegate and use the external callback set function doesn't work. The...
1
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
Jon Skeet wrote in the .NET general newsgroup 11/17/2005: "The difference between Invoke and DynamicInvoke is that the parameters to Invoke depend on the delegate itself - the method has the same...
3
by: GTAPy | last post by:
Hello Python Dev. i am new to Python, i am stuck in one of the classes instantiation with confusing __init__ , here the details : i have 2 classes Class A: def __init__(self): ...
1
by: someone help | last post by:
hi, i am very new in the software field. i have two child forms. i want two display image in picture box in one child form. when test is completed this image is displayed. i created one class and...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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,...

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.