473,230 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

Triggering event, listbox

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
8 2322
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
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
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
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
1
by: OhFiddleSticks | last post by:
Does anyone know if there is a way to add a text value to a combo box (the text box part, not the rowsource) in VBA without triggering an update event? I've tried everything I can think of without...
1
by: Wavemaker | last post by:
I was wondering if there is a way to change the value of a control without triggering an event. The ComboBox control, for example, will trigger the SelectedIndexChanged event when its SelectedIndex...
1
by: RedGST | last post by:
Hello, Im somewhat new to asp.net, so bear with me. I have created a form that has a Listbox along with 2 command buttons & a few other non-important controls. The command button is tied to...
1
by: amber | last post by:
Hello, How can I capture data in a listbox that occurs BEFORE the selected item switches from one item to another? myListbox.validating triggers after the user has left the listbox. ...
1
by: tony | last post by:
Hello! If you drag a ListBox into a windowform and then right click on this ListBox and then chose property. When you have the properties up click on the flash symbol for seeing all the events...
1
by: superjacent | last post by:
Hope someone can point me in the right direction. When opening a form the 'click' event of the ListBox is invoked (run). I thought the 'click' event of the ListBox is only invoked when clicking...
5
by: Vincent | last post by:
I have a bound listbox control on one of my forms that has an associated afterupdate event. When this event is invoked, I lock the control to prevent the user from clicking on it more than once....
0
by: BillCo | last post by:
I'm a C# Newbie, so if I've missed the obvious here go easy!!! I have a form opened from a MDI parent. The form has a data bound combo box, with a SelectedIndexChanged event (fills a list view...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.