[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

User Control Event

Posted on 2004-11-18
3
Medium Priority
?
362 Views
Last Modified: 2006-11-17
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

'___________________________________________________________________
0
Comment
Question by:lengreen
3 Comments
 
LVL 33

Assisted Solution

by:raterus
raterus earned 500 total points
ID: 12614705
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
 
LVL 22

Accepted Solution

by:
CJ_S earned 500 total points
ID: 12614722
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
 
LVL 10

Author Comment

by:lengreen
ID: 12614784
Cheers Guys

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

cheers

Len
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question