By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

Triggering event, listbox

P: n/a
For some reason I cannot get the OnSelectedIndexChanged event to fire for a
listbox I have on a page. I'm able to populate the listbox with data from a
stored procedure, but cannot trigger the event. I do have EnableViewState =
True for the listbox. I'm imagining (wanting) to populate the listbox named:
lstNames by using the DataValueField from lstDepartments.

It's quite apparent though that the event is not triggering as I can misname
the stored procedure and no error occurs.

Here is the code, I'm sure it will wrap terribly however::

MGSurvey.aspx:

<FORM id="MGSurvey" runat="server">
<p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
<asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION: relative;
TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged =
"lstDepartments_SelectedIndexChanged" Width="258px"
Height="118px"></asp:listbox>
<asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION: relative"
runat="server" Width="559px" Height="144px" BackColor="Transparent"
BorderColor="Transparent">
<asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
relative; TOP: 20px" runat="server" Width="258px" EnableViewState="True"
BackColor="Transparent"></asp:listbox>
</asp:panel>
</p>
</FORM>

MGSurvey.aspx.vb:

Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object, ByVal
e As EventArgs)

If (Not IsPostBack) Then
adoConn.Open()
Dim adoCommDeptMembers As New SqlCommand("dbo.MG_EmployeesByDepartment "
& lstDepartments.SelectedItem.Value, adoConn)

With lstNames
.DataSource =
adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
.DataTextField = "Name"
.DataValueField = "tp_ID"
.DataBind()
End With
adoConn.Close()

End If

End Sub
Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
How is the user triggering a postback to the server?

What happens when the page posts back to the server? What does it all look
like?

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:ez*************@TK2MSFTNGP11.phx.gbl...
For some reason I cannot get the OnSelectedIndexChanged event to fire for
a
listbox I have on a page. I'm able to populate the listbox with data from
a
stored procedure, but cannot trigger the event. I do have EnableViewState
=
True for the listbox. I'm imagining (wanting) to populate the listbox
named:
lstNames by using the DataValueField from lstDepartments.

It's quite apparent though that the event is not triggering as I can
misname
the stored procedure and no error occurs.

Here is the code, I'm sure it will wrap terribly however::

MGSurvey.aspx:

<FORM id="MGSurvey" runat="server">
<p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
<asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION: relative;
TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged =
"lstDepartments_SelectedIndexChanged" Width="258px"
Height="118px"></asp:listbox>
<asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
relative"
runat="server" Width="559px" Height="144px" BackColor="Transparent"
BorderColor="Transparent">
<asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
relative; TOP: 20px" runat="server" Width="258px" EnableViewState="True"
BackColor="Transparent"></asp:listbox>
</asp:panel>
</p>
</FORM>

MGSurvey.aspx.vb:

Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object,
ByVal
e As EventArgs)

If (Not IsPostBack) Then
adoConn.Open()
Dim adoCommDeptMembers As New SqlCommand("dbo.MG_EmployeesByDepartment
"
& lstDepartments.SelectedItem.Value, adoConn)

With lstNames
.DataSource =
adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
.DataTextField = "Name"
.DataValueField = "tp_ID"
.DataBind()
End With
adoConn.Close()

End If

End Sub

Nov 19 '05 #2

P: n/a
Well, I have two listboxes.

lstDepartments - Lists Departments
lstNames - Lists Members of Departments

On Page Load lstDepartments is loaded with a list of departments, with the
department 'code' as the DataValueField.

What I want to happen is, when you click on an item in the list of
departments, lstNames gets populated with the members of that department.

Stored procedures worked, tested them, they have the proper permissions,
etc.

Just can't seem to get OnSelectedIndexChanged to fire...I've tried with 'Not
IsPostBack' and without it...not sure how else to answer your
question...thanks! :)
"Marina" <so*****@nospam.com> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...
How is the user triggering a postback to the server?

What happens when the page posts back to the server? What does it all look
like?

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:ez*************@TK2MSFTNGP11.phx.gbl...
For some reason I cannot get the OnSelectedIndexChanged event to fire for a
listbox I have on a page. I'm able to populate the listbox with data from a
stored procedure, but cannot trigger the event. I do have EnableViewState =
True for the listbox. I'm imagining (wanting) to populate the listbox
named:
lstNames by using the DataValueField from lstDepartments.

It's quite apparent though that the event is not triggering as I can
misname
the stored procedure and no error occurs.

Here is the code, I'm sure it will wrap terribly however::

MGSurvey.aspx:

<FORM id="MGSurvey" runat="server">
<p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
<asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION: relative; TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged =
"lstDepartments_SelectedIndexChanged" Width="258px"
Height="118px"></asp:listbox>
<asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
relative"
runat="server" Width="559px" Height="144px" BackColor="Transparent"
BorderColor="Transparent">
<asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
relative; TOP: 20px" runat="server" Width="258px" EnableViewState="True"
BackColor="Transparent"></asp:listbox>
</asp:panel>
</p>
</FORM>

MGSurvey.aspx.vb:

Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object,
ByVal
e As EventArgs)

If (Not IsPostBack) Then
adoConn.Open()
Dim adoCommDeptMembers As New SqlCommand("dbo.MG_EmployeesByDepartment "
& lstDepartments.SelectedItem.Value, adoConn)

With lstNames
.DataSource =
adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
.DataTextField = "Name"
.DataValueField = "tp_ID"
.DataBind()
End With
adoConn.Close()

End If

End Sub


Nov 19 '05 #3

P: n/a
You didn't really answer my questions at all, so I'm sorry but I don't have
any ideas on how to help you.

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
Well, I have two listboxes.

lstDepartments - Lists Departments
lstNames - Lists Members of Departments

On Page Load lstDepartments is loaded with a list of departments, with the
department 'code' as the DataValueField.

What I want to happen is, when you click on an item in the list of
departments, lstNames gets populated with the members of that department.

Stored procedures worked, tested them, they have the proper permissions,
etc.

Just can't seem to get OnSelectedIndexChanged to fire...I've tried with
'Not
IsPostBack' and without it...not sure how else to answer your
question...thanks! :)
"Marina" <so*****@nospam.com> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...
How is the user triggering a postback to the server?

What happens when the page posts back to the server? What does it all
look
like?

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:ez*************@TK2MSFTNGP11.phx.gbl...
> For some reason I cannot get the OnSelectedIndexChanged event to fire for > a
> listbox I have on a page. I'm able to populate the listbox with data from > a
> stored procedure, but cannot trigger the event. I do have EnableViewState > =
> True for the listbox. I'm imagining (wanting) to populate the listbox
> named:
> lstNames by using the DataValueField from lstDepartments.
>
> It's quite apparent though that the event is not triggering as I can
> misname
> the stored procedure and no error occurs.
>
> Here is the code, I'm sure it will wrap terribly however::
>
> MGSurvey.aspx:
>
> <FORM id="MGSurvey" runat="server">
> <p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
> <asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION: relative; > TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged
> =
> "lstDepartments_SelectedIndexChanged" Width="258px"
> Height="118px"></asp:listbox>
> <asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
> relative"
> runat="server" Width="559px" Height="144px" BackColor="Transparent"
> BorderColor="Transparent">
> <asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
> relative; TOP: 20px" runat="server" Width="258px"
> EnableViewState="True"
> BackColor="Transparent"></asp:listbox>
> </asp:panel>
> </p>
> </FORM>
>
> MGSurvey.aspx.vb:
>
> Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object,
> ByVal
> e As EventArgs)
>
> If (Not IsPostBack) Then
> adoConn.Open()
> Dim adoCommDeptMembers As New SqlCommand("dbo.MG_EmployeesByDepartment > "
> & lstDepartments.SelectedItem.Value, adoConn)
>
> With lstNames
> .DataSource =
> adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
> .DataTextField = "Name"
> .DataValueField = "tp_ID"
> .DataBind()
> End With
> adoConn.Close()
>
> End If
>
> End Sub
>
>



Nov 19 '05 #4

P: n/a
"How is the user triggering a postback to the server?" - Postback, as I understand it is triggered by reloading the page. In my case, this is not happening. All the user should be doing is selecting with their mouse and item in the listbox, and hopefully triggering the OnSelectedIndexChanged event of the listbox named lstDepartments.

"What happens when the page posts back to the server? What does it all look like?" - Nothing happens, the first listbox flickers when you select an item, and the second listbox remains empty, and no error message occurs.

"Marina" <so*****@nospam.com> wrote in message news:uJ**************@TK2MSFTNGP12.phx.gbl...
You didn't really answer my questions at all, so I'm sorry but I don't have
any ideas on how to help you.

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
Well, I have two listboxes.

lstDepartments - Lists Departments
lstNames - Lists Members of Departments

On Page Load lstDepartments is loaded with a list of departments, with the
department 'code' as the DataValueField.

What I want to happen is, when you click on an item in the list of
departments, lstNames gets populated with the members of that department.

Stored procedures worked, tested them, they have the proper permissions,
etc.

Just can't seem to get OnSelectedIndexChanged to fire...I've tried with
'Not
IsPostBack' and without it...not sure how else to answer your
question...thanks! :)
"Marina" <so*****@nospam.com> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...
How is the user triggering a postback to the server?

What happens when the page posts back to the server? What does it all
look
like?

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:ez*************@TK2MSFTNGP11.phx.gbl...
> For some reason I cannot get the OnSelectedIndexChanged event to fire

for
> a
> listbox I have on a page. I'm able to populate the listbox with data

from
> a
> stored procedure, but cannot trigger the event. I do have

EnableViewState
> =
> True for the listbox. I'm imagining (wanting) to populate the listbox
> named:
> lstNames by using the DataValueField from lstDepartments.
>
> It's quite apparent though that the event is not triggering as I can
> misname
> the stored procedure and no error occurs.
>
> Here is the code, I'm sure it will wrap terribly however::
>
> MGSurvey.aspx:
>
> <FORM id="MGSurvey" runat="server">
> <p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
> <asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION:

relative;
> TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged
> =
> "lstDepartments_SelectedIndexChanged" Width="258px"
> Height="118px"></asp:listbox>
> <asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
> relative"
> runat="server" Width="559px" Height="144px" BackColor="Transparent"
> BorderColor="Transparent">
> <asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
> relative; TOP: 20px" runat="server" Width="258px"
> EnableViewState="True"
> BackColor="Transparent"></asp:listbox>
> </asp:panel>
> </p>
> </FORM>
>
> MGSurvey.aspx.vb:
>
> Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object,
> ByVal
> e As EventArgs)
>
> If (Not IsPostBack) Then
> adoConn.Open()
> Dim adoCommDeptMembers As New

SqlCommand("dbo.MG_EmployeesByDepartment
> "
> & lstDepartments.SelectedItem.Value, adoConn)
>
> With lstNames
> .DataSource =
> adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
> .DataTextField = "Name"
> .DataValueField = "tp_ID"
> .DataBind()
> End With
> adoConn.Close()
>
> End If
>
> End Sub
>
>




Nov 19 '05 #5

P: n/a
Ok, so the problem is that there is no postback to the server!

A server side event can't run, unless something forces a postback to the server. Your page is sitting in the browser - whatever objects the server used to generate the page are long gone. HTTP is a connectionless protocol - it's just the browser on its own.

So you need something there to trigger an event to the server.

I think the listbox may be one of the objects that has an AutoPostback property. If it does, setting this to True, will trigger a postback to the server whenever the selected item is changed.
If the listbox does not have such a property, you need to trigger a postback. It may be that there is a button the user has to click to proceed, or you may have to write some javascript to trigger the post.
"Steve Schroeder" <ss********@somewhere.com> wrote in message news:e0**************@TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I understand it is triggered by reloading the page. In my case, this is not happening. All the user should be doing is selecting with their mouse and item in the listbox, and hopefully triggering the OnSelectedIndexChanged event of the listbox named lstDepartments.

"What happens when the page posts back to the server? What does it all look like?" - Nothing happens, the first listbox flickers when you select an item, and the second listbox remains empty, and no error message occurs.

"Marina" <so*****@nospam.com> wrote in message news:uJ**************@TK2MSFTNGP12.phx.gbl...
You didn't really answer my questions at all, so I'm sorry but I don't have
any ideas on how to help you.

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
Well, I have two listboxes.

lstDepartments - Lists Departments
lstNames - Lists Members of Departments

On Page Load lstDepartments is loaded with a list of departments, with the
department 'code' as the DataValueField.

What I want to happen is, when you click on an item in the list of
departments, lstNames gets populated with the members of that department.

Stored procedures worked, tested them, they have the proper permissions,
etc.

Just can't seem to get OnSelectedIndexChanged to fire...I've tried with
'Not
IsPostBack' and without it...not sure how else to answer your
question...thanks! :)
"Marina" <so*****@nospam.com> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...
How is the user triggering a postback to the server?

What happens when the page posts back to the server? What does it all
look
like?

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:ez*************@TK2MSFTNGP11.phx.gbl...
> For some reason I cannot get the OnSelectedIndexChanged event to fire

for
> a
> listbox I have on a page. I'm able to populate the listbox with data

from
> a
> stored procedure, but cannot trigger the event. I do have

EnableViewState
> =
> True for the listbox. I'm imagining (wanting) to populate the listbox
> named:
> lstNames by using the DataValueField from lstDepartments.
>
> It's quite apparent though that the event is not triggering as I can
> misname
> the stored procedure and no error occurs.
>
> Here is the code, I'm sure it will wrap terribly however::
>
> MGSurvey.aspx:
>
> <FORM id="MGSurvey" runat="server">
> <p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
> <asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION:

relative;
> TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged
> =
> "lstDepartments_SelectedIndexChanged" Width="258px"
> Height="118px"></asp:listbox>
> <asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
> relative"
> runat="server" Width="559px" Height="144px" BackColor="Transparent"
> BorderColor="Transparent">
> <asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
> relative; TOP: 20px" runat="server" Width="258px"
> EnableViewState="True"
> BackColor="Transparent"></asp:listbox>
> </asp:panel>
> </p>
> </FORM>
>
> MGSurvey.aspx.vb:
>
> Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object,
> ByVal
> e As EventArgs)
>
> If (Not IsPostBack) Then
> adoConn.Open()
> Dim adoCommDeptMembers As New

SqlCommand("dbo.MG_EmployeesByDepartment
> "
> & lstDepartments.SelectedItem.Value, adoConn)
>
> With lstNames
> .DataSource =
> adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
> .DataTextField = "Name"
> .DataValueField = "tp_ID"
> .DataBind()
> End With
> adoConn.Close()
>
> End If
>
> End Sub
>
>




Nov 19 '05 #6

P: n/a
Well I'll be damned...that worked! Thank you!

For future reference...when would I not want to do a postback, and if 90% of the time people do postback, why isn't it the default behavior? I would have gnashed my teeth over that one indefinately...
"Marina" <so*****@nospam.com> wrote in message news:O6*************@TK2MSFTNGP09.phx.gbl...
Ok, so the problem is that there is no postback to the server!

A server side event can't run, unless something forces a postback to the server. Your page is sitting in the browser - whatever objects the server used to generate the page are long gone. HTTP is a connectionless protocol - it's just the browser on its own.

So you need something there to trigger an event to the server.

I think the listbox may be one of the objects that has an AutoPostback property. If it does, setting this to True, will trigger a postback to the server whenever the selected item is changed.
If the listbox does not have such a property, you need to trigger a postback. It may be that there is a button the user has to click to proceed, or you may have to write some javascript to trigger the post.
"Steve Schroeder" <ss********@somewhere.com> wrote in message news:e0**************@TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I understand it is triggered by reloading the page. In my case, this is not happening. All the user should be doing is selecting with their mouse and item in the listbox, and hopefully triggering the OnSelectedIndexChanged event of the listbox named lstDepartments.

"What happens when the page posts back to the server? What does it all look like?" - Nothing happens, the first listbox flickers when you select an item, and the second listbox remains empty, and no error message occurs.

"Marina" <so*****@nospam.com> wrote in message news:uJ**************@TK2MSFTNGP12.phx.gbl...
You didn't really answer my questions at all, so I'm sorry but I don't have
any ideas on how to help you.

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
Well, I have two listboxes.

lstDepartments - Lists Departments
lstNames - Lists Members of Departments

On Page Load lstDepartments is loaded with a list of departments, with the
department 'code' as the DataValueField.

What I want to happen is, when you click on an item in the list of
departments, lstNames gets populated with the members of that department.

Stored procedures worked, tested them, they have the proper permissions,
etc.

Just can't seem to get OnSelectedIndexChanged to fire...I've tried with
'Not
IsPostBack' and without it...not sure how else to answer your
question...thanks! :)
"Marina" <so*****@nospam.com> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...
How is the user triggering a postback to the server?

What happens when the page posts back to the server? What does it all
look
like?

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:ez*************@TK2MSFTNGP11.phx.gbl...
> For some reason I cannot get the OnSelectedIndexChanged event to fire

for
> a
> listbox I have on a page. I'm able to populate the listbox with data

from
> a
> stored procedure, but cannot trigger the event. I do have

EnableViewState
> =
> True for the listbox. I'm imagining (wanting) to populate the listbox
> named:
> lstNames by using the DataValueField from lstDepartments.
>
> It's quite apparent though that the event is not triggering as I can
> misname
> the stored procedure and no error occurs.
>
> Here is the code, I'm sure it will wrap terribly however::
>
> MGSurvey.aspx:
>
> <FORM id="MGSurvey" runat="server">
> <p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
> <asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION:

relative;
> TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged
> =
> "lstDepartments_SelectedIndexChanged" Width="258px"
> Height="118px"></asp:listbox>
> <asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
> relative"
> runat="server" Width="559px" Height="144px" BackColor="Transparent"
> BorderColor="Transparent">
> <asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
> relative; TOP: 20px" runat="server" Width="258px"
> EnableViewState="True"
> BackColor="Transparent"></asp:listbox>
> </asp:panel>
> </p>
> </FORM>
>
> MGSurvey.aspx.vb:
>
> Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object,
> ByVal
> e As EventArgs)
>
> If (Not IsPostBack) Then
> adoConn.Open()
> Dim adoCommDeptMembers As New

SqlCommand("dbo.MG_EmployeesByDepartment
> "
> & lstDepartments.SelectedItem.Value, adoConn)
>
> With lstNames
> .DataSource =
> adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
> .DataTextField = "Name"
> .DataValueField = "tp_ID"
> .DataBind()
> End With
> adoConn.Close()
>
> End If
>
> End Sub
>
>




Nov 19 '05 #7

P: n/a
Because, who is to say that you always want a postback?

A lot of times, a user is filling out a form, and has many fields to fill out. Then they hit 'Submit', and go to the next page. In this case you would not want to postback automatically. Not only because there is nothing to do until the form is filled out, but because it is a waste of resources, and looks ugly with the screen flashing all the time.

So I would say, that it is not the case that people want to postback most of the time. It really just depends on the type of application and what the UI needs to do.

I think most people would assume that nothing happens by default, because that is what HTML equivalents of these controls would do. And then they add code to change the default behavior.
"Steve Schroeder" <ss********@somewhere.com> wrote in message news:OF**************@TK2MSFTNGP15.phx.gbl...
Well I'll be damned...that worked! Thank you!

For future reference...when would I not want to do a postback, and if 90% of the time people do postback, why isn't it the default behavior? I would have gnashed my teeth over that one indefinately...
"Marina" <so*****@nospam.com> wrote in message news:O6*************@TK2MSFTNGP09.phx.gbl...
Ok, so the problem is that there is no postback to the server!

A server side event can't run, unless something forces a postback to the server. Your page is sitting in the browser - whatever objects the server used to generate the page are long gone. HTTP is a connectionless protocol - it's just the browser on its own.

So you need something there to trigger an event to the server.

I think the listbox may be one of the objects that has an AutoPostback property. If it does, setting this to True, will trigger a postback to the server whenever the selected item is changed.
If the listbox does not have such a property, you need to trigger a postback. It may be that there is a button the user has to click to proceed, or you may have to write some javascript to trigger the post.
"Steve Schroeder" <ss********@somewhere.com> wrote in message news:e0**************@TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I understand it is triggered by reloading the page. In my case, this is not happening. All the user should be doing is selecting with their mouse and item in the listbox, and hopefully triggering the OnSelectedIndexChanged event of the listbox named lstDepartments.

"What happens when the page posts back to the server? What does it all look like?" - Nothing happens, the first listbox flickers when you select an item, and the second listbox remains empty, and no error message occurs.

"Marina" <so*****@nospam.com> wrote in message news:uJ**************@TK2MSFTNGP12.phx.gbl...
You didn't really answer my questions at all, so I'm sorry but I don't have
any ideas on how to help you.

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
Well, I have two listboxes.

lstDepartments - Lists Departments
lstNames - Lists Members of Departments

On Page Load lstDepartments is loaded with a list of departments, with the
department 'code' as the DataValueField.

What I want to happen is, when you click on an item in the list of
departments, lstNames gets populated with the members of that department.

Stored procedures worked, tested them, they have the proper permissions,
etc.

Just can't seem to get OnSelectedIndexChanged to fire...I've tried with
'Not
IsPostBack' and without it...not sure how else to answer your
question...thanks! :)
"Marina" <so*****@nospam.com> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...
How is the user triggering a postback to the server?

What happens when the page posts back to the server? What does it all
look
like?

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:ez*************@TK2MSFTNGP11.phx.gbl...
> For some reason I cannot get the OnSelectedIndexChanged event to fire

for
> a
> listbox I have on a page. I'm able to populate the listbox with data

from
> a
> stored procedure, but cannot trigger the event. I do have

EnableViewState
> =
> True for the listbox. I'm imagining (wanting) to populate the listbox
> named:
> lstNames by using the DataValueField from lstDepartments.
>
> It's quite apparent though that the event is not triggering as I can
> misname
> the stored procedure and no error occurs.
>
> Here is the code, I'm sure it will wrap terribly however::
>
> MGSurvey.aspx:
>
> <FORM id="MGSurvey" runat="server">
> <p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
> <asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION:

relative;
> TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged
> =
> "lstDepartments_SelectedIndexChanged" Width="258px"
> Height="118px"></asp:listbox>
> <asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
> relative"
> runat="server" Width="559px" Height="144px" BackColor="Transparent"
> BorderColor="Transparent">
> <asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
> relative; TOP: 20px" runat="server" Width="258px"
> EnableViewState="True"
> BackColor="Transparent"></asp:listbox>
> </asp:panel>
> </p>
> </FORM>
>
> MGSurvey.aspx.vb:
>
> Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object,
> ByVal
> e As EventArgs)
>
> If (Not IsPostBack) Then
> adoConn.Open()
> Dim adoCommDeptMembers As New

SqlCommand("dbo.MG_EmployeesByDepartment
> "
> & lstDepartments.SelectedItem.Value, adoConn)
>
> With lstNames
> .DataSource =
> adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
> .DataTextField = "Name"
> .DataValueField = "tp_ID"
> .DataBind()
> End With
> adoConn.Close()
>
> End If
>
> End Sub
>
>




Nov 19 '05 #8

P: n/a
I appreciate the great explanation. Thank you.
"Marina" <so*****@nospam.com> wrote in message news:uQ**************@TK2MSFTNGP12.phx.gbl...
Because, who is to say that you always want a postback?

A lot of times, a user is filling out a form, and has many fields to fill out. Then they hit 'Submit', and go to the next page. In this case you would not want to postback automatically. Not only because there is nothing to do until the form is filled out, but because it is a waste of resources, and looks ugly with the screen flashing all the time.

So I would say, that it is not the case that people want to postback most of the time. It really just depends on the type of application and what the UI needs to do.

I think most people would assume that nothing happens by default, because that is what HTML equivalents of these controls would do. And then they add code to change the default behavior.
"Steve Schroeder" <ss********@somewhere.com> wrote in message news:OF**************@TK2MSFTNGP15.phx.gbl...
Well I'll be damned...that worked! Thank you!

For future reference...when would I not want to do a postback, and if 90% of the time people do postback, why isn't it the default behavior? I would have gnashed my teeth over that one indefinately...
"Marina" <so*****@nospam.com> wrote in message news:O6*************@TK2MSFTNGP09.phx.gbl...
Ok, so the problem is that there is no postback to the server!

A server side event can't run, unless something forces a postback to the server. Your page is sitting in the browser - whatever objects the server used to generate the page are long gone. HTTP is a connectionless protocol - it's just the browser on its own.

So you need something there to trigger an event to the server.

I think the listbox may be one of the objects that has an AutoPostback property. If it does, setting this to True, will trigger a postback to the server whenever the selected item is changed.
If the listbox does not have such a property, you need to trigger a postback. It may be that there is a button the user has to click to proceed, or you may have to write some javascript to trigger the post.
"Steve Schroeder" <ss********@somewhere.com> wrote in message news:e0**************@TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I understand it is triggered by reloading the page. In my case, this is not happening. All the user should be doing is selecting with their mouse and item in the listbox, and hopefully triggering the OnSelectedIndexChanged event of the listbox named lstDepartments.

"What happens when the page posts back to the server? What does it all look like?" - Nothing happens, the first listbox flickers when you select an item, and the second listbox remains empty, and no error message occurs.

"Marina" <so*****@nospam.com> wrote in message news:uJ**************@TK2MSFTNGP12.phx.gbl...
You didn't really answer my questions at all, so I'm sorry but I don't have
any ideas on how to help you.

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
Well, I have two listboxes.

lstDepartments - Lists Departments
lstNames - Lists Members of Departments

On Page Load lstDepartments is loaded with a list of departments, with the
department 'code' as the DataValueField.

What I want to happen is, when you click on an item in the list of
departments, lstNames gets populated with the members of that department.

Stored procedures worked, tested them, they have the proper permissions,
etc.

Just can't seem to get OnSelectedIndexChanged to fire...I've tried with
'Not
IsPostBack' and without it...not sure how else to answer your
question...thanks! :)
"Marina" <so*****@nospam.com> wrote in message
news:er**************@TK2MSFTNGP14.phx.gbl...
How is the user triggering a postback to the server?

What happens when the page posts back to the server? What does it all
look
like?

"Steve Schroeder" <ss********@somewhere.com> wrote in message
news:ez*************@TK2MSFTNGP11.phx.gbl...
> For some reason I cannot get the OnSelectedIndexChanged event to fire

for
> a
> listbox I have on a page. I'm able to populate the listbox with data

from
> a
> stored procedure, but cannot trigger the event. I do have

EnableViewState
> =
> True for the listbox. I'm imagining (wanting) to populate the listbox
> named:
> lstNames by using the DataValueField from lstDepartments.
>
> It's quite apparent though that the event is not triggering as I can
> misname
> the stored procedure and no error occurs.
>
> Here is the code, I'm sure it will wrap terribly however::
>
> MGSurvey.aspx:
>
> <FORM id="MGSurvey" runat="server">
> <p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
> <asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION:

relative;
> TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged
> =
> "lstDepartments_SelectedIndexChanged" Width="258px"
> Height="118px"></asp:listbox>
> <asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
> relative"
> runat="server" Width="559px" Height="144px" BackColor="Transparent"
> BorderColor="Transparent">
> <asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
> relative; TOP: 20px" runat="server" Width="258px"
> EnableViewState="True"
> BackColor="Transparent"></asp:listbox>
> </asp:panel>
> </p>
> </FORM>
>
> MGSurvey.aspx.vb:
>
> Public Sub lstDepartments_SelectedIndexChanged(ByVal sender As Object,
> ByVal
> e As EventArgs)
>
> If (Not IsPostBack) Then
> adoConn.Open()
> Dim adoCommDeptMembers As New

SqlCommand("dbo.MG_EmployeesByDepartment
> "
> & lstDepartments.SelectedItem.Value, adoConn)
>
> With lstNames
> .DataSource =
> adoCommDeptMembers.ExecuteReader(CommandBehavior.C loseConnection)
> .DataTextField = "Name"
> .DataValueField = "tp_ID"
> .DataBind()
> End With
> adoConn.Close()
>
> End If
>
> End Sub
>
>




Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.