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(ByVa
l 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.CloseConnection)
.DataTextField = "Name"
.DataValueField = "tp_ID"
.DataBind()
End With
adoConn.Close()
End If
End SubHow 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" <sschroeder@.somewhere.com> wrote in message
news:ez4PuKNrFHA.260@.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(ByVa
l 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.CloseConnection)
> .DataTextField = "Name"
> .DataValueField = "tp_ID"
> .DataBind()
> End With
> adoConn.Close()
> End If
> End Sub
>
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" <someone@.nospam.com> wrote in message
news:erppRNNrFHA.3720@.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" <sschroeder@.somewhere.com> wrote in message
> news:ez4PuKNrFHA.260@.TK2MSFTNGP11.phx.gbl...
for
from
EnableViewState
relative;
SqlCommand("dbo.MG_EmployeesByDepartment
>
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" <sschroeder@.somewhere.com> wrote in message
news:u0gIWTNrFHA.2768@.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" <someone@.nospam.com> wrote in message
> news:erppRNNrFHA.3720@.TK2MSFTNGP14.phx.gbl...
> for
> from
> EnableViewState
> relative;
> SqlCommand("dbo.MG_EmployeesByDepartment
>
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e 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" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.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 ser
ver. 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 prope
rty. 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" <sschroeder@.somewhere.com> wrote in message news:e0RNqcNrF
HA.1128@.TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e 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" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.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 hav
e gnashed my teeth over that one indefinately...
"Marina" <someone@.nospam.com> wrote in message news:O6YP1gNrFHA.528@.TK2MSFTN
GP09.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 ser
ver. 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 prope
rty. 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" <sschroeder@.somewhere.com> wrote in message news:e0RNqcNrF
HA.1128@.TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e 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" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.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 ou
t. 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 l
ooks 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 th
at is what HTML equivalents of these controls would do. And then they add c
ode to change the default behavior.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message news:OFaBqoNrF
HA.2624@.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 hav
e gnashed my teeth over that one indefinately...
"Marina" <someone@.nospam.com> wrote in message news:O6YP1gNrFHA.528@.TK2MSFTN
GP09.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 ser
ver. 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 prope
rty. 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" <sschroeder@.somewhere.com> wrote in message news:e0RNqcNrF
HA.1128@.TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e 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" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.phx.gbl...
>
>
I appreciate the great explanation. Thank you.
"Marina" <someone@.nospam.com> wrote in message news:uQjFnrNrFHA.2880@.TK2MSFT
NGP12.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 ou
t. 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 l
ooks 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 th
at is what HTML equivalents of these controls would do. And then they add c
ode to change the default behavior.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message news:OFaBqoNrF
HA.2624@.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 hav
e gnashed my teeth over that one indefinately...
"Marina" <someone@.nospam.com> wrote in message news:O6YP1gNrFHA.528@.TK2MSFTN
GP09.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 ser
ver. 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 prope
rty. 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" <sschroeder@.somewhere.com> wrote in message news:e0RNqcNrF
HA.1128@.TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e 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" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.phx.gbl...
>
>
Saturday, March 31, 2012
Triggering event, listbox
Labels:
alistbox,
asp,
event,
fire,
listbox,
net,
onselectedindexchanged,
page,
populate,
triggering
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment