Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2007, 05:06 AM
Authorized User
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change return type of Click Event

Hi,
How to temperorily change return type of and even handler,

ie
if(btnCancel_Click(txtNew,new EventArgs()))
{
}

by default it returns Void.

but this same event requires return type as void at different junction. How to solve this..




Prasnana
__________________
Thanks

Prasanna
 
Old August 4th, 2007, 01:57 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

What you want to do or check?
 
Old August 4th, 2007, 02:07 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

You cannot change the return type of an event handler, as it is a delegate function.

Why do you not encapsulate the above logic in the event handler? Or create a delegate of your own that can take a Click Event Handler Delegate, and have its own return type?

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old August 4th, 2007, 08:06 AM
Authorized User
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the Reply.

I am Validating a textbox, and I should only proceed when i enter the textbox correctly and I should be able to cancel any time. I have used focus return that textbox, which disables cancel button. So I am checking only when Cancel button not pressed or event called that focus should return to the textbox.
Hope I am clear about the question.



Thanks

Prasanna
 
Old August 4th, 2007, 09:52 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

if(btnCancel_Click(txtNew,new EventArgs()))
{
}

Doing is this way is rather clumsy in my view. Why not perform the activity you need to perform in a secondary function which you can call from this code as well as the button click handler. Then that function can return the status required.

-Peter
 
Old August 4th, 2007, 11:17 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Not positive what you are driving at, but I think I get the basic idea, and I totally agree with planoie..

Sounds like you are using Form level validation, so why not (and I think this is pretty much standard practise) just create a method to validate all the fields(which can be composed of calls to other methods of there are a lot or the logic is complex)?

Maybe I have missed the mark, but I am really not sure as to how you came to logic choice you have??

I hope this gives you food for thought.

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old August 6th, 2007, 04:34 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

I think Peter's solution is correct. you can call another user defined function from btn_click event handler and return true or false from this function according to whether textbox value is validated successfully or not.
 
Old August 8th, 2007, 12:12 AM
Authorized User
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.

Let me refrain my Question.

I am validating a textbox which is present in one of the Tab Pages of the Form. For all the Tab pages we have a Common Save and Cancel button. I wanted to validate a textbox when "textbox.leave" of that textbox event occurs and user can press cancel button at any moment of the application.

Please let me know how should I implement this.



Thanks

Prasanna
 
Old August 8th, 2007, 01:49 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Prasanna,

In order to perform field level validation you need to do two things:
1. In the "Focus" properties category, set "CausesValidation" to true (should be this by default).

2. Create an Event Handler for "Validating" Event in the "Focus" events category.

You can then add your validation logic to this handler.
If you want to cancel the leaving of the field, you simply:
e.Cancel = true;.

You can also try:
http://www.examcram2.com/articles/ar...&seqNum=4&rl=1

I haven't read it all, but its an excerpt from a book designed for the MCP which I am working towards, and all this fundamental stuff is covered.

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old August 9th, 2007, 07:29 AM
Authorized User
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rob for you kind reply.

The Cancel button which I mentioned in my Question is main Cancel button of the form which the user uses to close or discard changes made to the form.
When we set focus to a control unless it contains right value in it, focus remains in the control. How to close the form irrespective of the focus.

I had used setfocus which was creating problem for me.



Thanks

Prasanna





Similar Threads
Thread Thread Starter Forum Replies Last Post
Generic return type mega C# 4 November 30th, 2006 11:00 AM
Generic return type mega C# 2005 1 November 30th, 2006 07:27 AM
return type? Sibananda Tripathy J2EE 1 January 3rd, 2005 04:03 AM
Click Event dkr72 C# 3 December 8th, 2004 06:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.