Print Page | Close Window

Multiple Handles in sub

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=6909
Printed Date: 29 March 2026 at 7:41am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Multiple Handles in sub
Posted By: Diep-Vriezer
Subject: Multiple Handles in sub
Date Posted: 01 November 2003 at 2:10pm

Hey,

I want a single sub to take care of all the links in a page, by using

Private Sub Links(..) Handles Link1.Click, Link2.Click

How am I going to know in the sub wich link the user pressed? I can make seperate subs, but I wanted to know if I can do it like this. So, can I?



-------------
Gone..



Replies:
Posted By: MorningZ
Date Posted: 01 November 2003 at 4:46pm

i wouldnt think thats possible, as the sub would have absolutely no idea what they clicked...

just save yourself time and write seperate functions (after all, if you want to know which is click, then you must be wanting to do different things)



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 01 November 2003 at 5:37pm

Are you sure? In VB6 (a long time ago..) they had things like If Case = "" and stuff. Is that completely gone in .NET?

I'm not sure. I'll keep trying, but idd, I already created seperate subs, wich is nog a big deal, but still, it supports multiple handles, so it must SOMEHOW know wich link is pressed.



-------------
Gone..


Posted By: MorningZ
Date Posted: 01 November 2003 at 7:15pm

just go with what works.. you said you already have seperate subs... do it...

and yes, VB.NET suppurts SELECT CASE



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 02 November 2003 at 3:45am

Can't you index controls so it would be something like

Private Sub Link_Click(Index As Integer) Handles link.click

Mart.



Posted By: Diep-Vriezer
Date Posted: 02 November 2003 at 4:24am

Uhh, no. It must always look like this

Private Sub Link_Click(sender As System.Object, e As System.Eventargs) Handles link.click

That's because the framework always sends those values, and it will result in an error if you don't have a sub looking like this..



-------------
Gone..


Posted By: Mart
Date Posted: 02 November 2003 at 9:35am

yea i know i couldnt be bothered writin all that out, like this then:

Private Sub Link_Click(Index As integer, sender As System.Object, e As System.Eventargs) Handles link.click

And on the links put Index="0" etc. Does that work?

Mart.



Posted By: Diep-Vriezer
Date Posted: 02 November 2003 at 12:27pm
I don't think so, since you can't tell wich stuff should be send to the sub when it is clicked, since the framework does that. Or I would have to crack the framework and stuff, but thats a bit to much I guess.

-------------
Gone..


Posted By: Mart
Date Posted: 02 November 2003 at 1:02pm

Nooo like in VB you put all the controls in a Index array and the Index value of:

Private Sub Link_Click(Index As integer, sender As System.Object, e As System.Eventargs) Handles link.click

changes to the control that was clicked.



Posted By: Diep-Vriezer
Date Posted: 02 November 2003 at 1:31pm
I'll give it a shot

-------------
Gone..


Posted By: MorningZ
Date Posted: 02 November 2003 at 1:31pm

i am still wondering why you wouldn't use different functions since the buttons (obviously) do different things....

seperating the logic seems to make a hell of a lot more sense than doing a case statement inside one function

not trying to be difficult on this thread, just severely questioning the logic



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 02 November 2003 at 1:35pm
A link button can't accept index stuff.

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 02 November 2003 at 3:00pm
Originally posted by MorningZ MorningZ wrote:

i am still wondering why you wouldn't use different functions since the buttons (obviously) do different things....

seperating the logic seems to make a hell of a lot more sense than doing a case statement inside one function

not trying to be difficult on this thread, just severely questioning the logic

The point is, they all do the same thing. But have this litte parameter wich needs to be set wich is different.

The midbar is made out of 11 linkbuttons, which are all dynamic. If I would have to write the code at each page, for each sub, that will add up to about 400 lines of code per page..  Got the point?



-------------
Gone..



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net