problems after a first postback

B

Ben

Hello

I create two dropdownlists, set their autopostback
property to true and instanciate a SelectedIndexChanged
for each of them (just binding some drop down lists ).

When I run the solution, everything works fine the first
time I change one of the drop down list. Once the first
postback done, no more event fires when I change a
dropdownlist. It seems that the event associated with
the ddl are no longer available.

Please help me with this...

Thanks a lot

Ben
 
D

Duray AKAR

Ben,

Does the selectedIndexChanged event fire after submitting
the form by other means (like a submit button), or it does
not fire at all?

You might be doing something in the postback event that
will result indirectly in modifying the autopostback
property, or even deattach the event handlers...

or adding the event handlers in codebehind in page_load
instead of having them them on the aspx page and having
them in the WebForm generated code section might result in
this situation too(in c#)..

can you post the code ?

Duray
 
B

Ben

Thank you for such a fast reply

The selectedIndexChanged fire the first time ,
initializing another list, but nothing is happening if I
change the selection again after.

Here is the code...I'm still a beginner on .net (also in
english ;( )

Code:
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

'If it's the real page load
If Not Page.IsPostBack Then

InitializeDDL()
DDLGroupe.Enabled = False

End If

End Sub

Private Sub InitializeDDL()

' Initialize the general drop down lists
InitializeDDLDepartement()
InitializeDDLVille()
InitializeDDLSite()
InitializeDDLHoraire()
InitializeDDLChambre()
InitializeDDLChambreBloque()


End Sub

' ** All the other initialize are the same **
Private Sub InitializeDDLDepartement()

' open the connection
cn.Open()
Dim sql As String = "SELECT DISTINCT
DepartementID, Nom FROM Departement"

Dim cmd As New SqlCommand(sql, cn)

'Bind the DDL
DDLDept.DataSource = cmd.ExecuteReader()
DDLDept.DataTextField = "Nom"
DDLDept.DataValueField = "DepartementId"
DDLDept.DataBind()
'Close the connection
cn.Close()
End Sub

' Here's the selectedIndexChanged
Private Sub DDLDept_selectedIndexChanged(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
DDLDept.SelectedIndexChanged

' enabled the ddl
DDLGroupe.Enabled = True

' establish the connexion
cn.Open()

' SQL request used to bind the DDL
Dim sql As String = " Select anything FROM
anything WHERE (Departement.DepartementId = " &
DDLDept.SelectedItem.Value & ")"

Dim cmd As New SqlCommand(sql, cn)

'Bind the DDL
DDLGroupe.DataSource = cmd.ExecuteReader()
DDLGroupe.DataTextField = "Nom"
DDLGroupe.DataValueField = "GroupeId"
DDLGroupe.DataBind()
'Fermer les connexions
cn.Close()

End Sub

Is there any way to associate the selectedIndexChanged of
a DDL with an event directly in the page load?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top