Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Handles' clause occasionally vanishes from code-behind

Status
Not open for further replies.

abds

Programmer
Dec 13, 2000
46
0
0
US
I am using VisualStudio.NET 2003
When I write a simple handler such as:

Private Sub EndBtn_Click(object, event) handles EndBtn.Click
Response.Redirect("Comp.aspx")
End Sub

Sometimes the "Handles EndBtn.Click" vanishes from my code.
When I double click the button in design view, the clause reappears in the code-behind.

I see no pattern to this behaviour.

Why does this happen and can I prevent it?

tyia,

Phil

We are drowning in data, but we are starving for information.
 
Yep
We've all been there. It is quite annoying when events seem to stop firing.
I don't know if there is a solution, but there is a workaround.
You can call the AddHandler routine (it is quite simple - look in help for it) during the page load or page init to associate subroutines with events, and delete all your handles clauses.
This is pretty much how C# does it - you don't get handles in C#.

Hope this helps.


Mark [openup]
 
Oh I forgot - there is another solution, which involves setting the AutoEventWireUp property of the page (at the top of the HTML).
Then, it reverts to VB6 style code, where the name of the sub is implicitly linked to the event, for example Button1_Click().
With this, I think you can still use AddHandler as well, if you want.



Mark [openup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top