User Control Event

Hi

I have a user contol in my main page that has a dropdownlist, I can easily add a new event handler for the
SelectedIndexChanged event of the ddl (as below), but i want the ChangeDestination Sub fired immediately, so instead of getting an output of 1 2 3 (which it is at the moment) it would be 1 3 2, hope this is clear

cheers

Len

'Main Page
'_____________________________________________________

Public Class dest
  Inherits System.Web.UI.Page

  Protected WithEvents DEST As __destinations

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Response.Write("1 ")
    AddHandler DEST.ddlDestinations.SelectedIndexChanged, AddressOf ChangeDestination
    Response.Write("2 ")
  End Sub


  Sub ChangeDestination(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Response.Write("3 ")
  End Sub

End Class

'___________________________________________________________________
LVL 10
lengreenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

raterusCommented:
I think you may be trying to do too much in Page Load.  Why not let the Page Load finish it's work, then let your ChangeDestination Sub handle most everything else.  And why are you explicitly calling AddHandler like that?  Can't you just do this?

 Sub ChangeDestination(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dest.SelectedIndexChanged
    Response.Write("3 ")
    Response.Write("2 ")
  End Sub

Then in your usercontrol, define an event "SelectedIndexChanged", and raise that in the ddl's event handler.  The is the proper way to handle events.  You shouldn't have to ever look at yucky AddHandler Code like that in Page_Load.

This probably isn't chear :-)
0
CJ_SCommented:
Why? The index hasn't changed at all. So why would you want it to fire?

An easy fix would be:



Public Class dest
  Inherits System.Web.UI.Page

  Protected WithEvents DEST As __destinations

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Response.Write("1 ")
    AddHandler DEST.ddlDestinations.SelectedIndexChanged, AddressOf ChangeDestination
    ChangeDestination(New EventArgs())
    Response.Write("2 ")
  End Sub
 
  Protected Overridable Sub OnChangeDestination(ByVal e as EventArgs)
        ChangeDestination(Me, e)
  End Sub


  Protected Overridable Sub ChangeDestination(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Response.Write("3 ")
  End Sub

End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lengreenAuthor Commented:
Cheers Guys

I was thinking too complex, I must remember to keep it simple :)

cheers

Len
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.