470,631 Members | 1,607 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

[LISTBOX] AutoPostBack not fired with EnableViewState = False

teo
I have a Listbox,

if I set
EnableViewStarte = False
the
AutopostaBack fired by SelectedIndexChanged
doesn't work.
The 'SelectedIndexChanged' event should call
a sub called 'SayHalloPlease'.
Any Idea?

Here my simple code:
a Button
a Listbox
a Textbox

with Listbox EnableViewState = True it works
with Listbox EnableViewState = False it doesn't work

( AspNet 20 VisualStudio 2005 )

--- here the Code behind: ---------------------------------
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
MsgBox("I've been fired!")
SayHalloPlease(ListBox1.SelectedIndex)
End Sub

Private Sub SayHalloPlease(ByVal myNumber As Integer)
If myNumber = 2 Then TextBox1.Text = TextBox1.Text & "Hallo"
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.Items.Add("aaaaa")
ListBox1.Items.Add("bbbbb")
ListBox1.Items.Add("cccccThis")
ListBox1.Items.Add("ddddd")
ListBox1.Items.Add("eeeee")
End Sub
---- here the Asp code: -------------------------------------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
Style="z-index: 100; left: 284px; position: absolute; top:
40px">
</asp:ListBox>
&nbsp;
<asp:Button ID="Button1" runat="server" Style="z-index: 102; left:
164px; position: absolute;
top: 48px" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 104;
left: 472px; position: absolute;
top: 64px"></asp:TextBox>

</div>
</form>
</body>
</html>
Sep 28 '06 #1
2 2775
if you turn off viewstate, then the control does not send the list of
dropdown values to the page. thus when the postback value is applied there
is no matching value in the list (as the control can not reconstruct it).

in the oninit of the postback after the click (before postback data is
applied) you need to re-add the list values added by the onclick of the
previous render. hint: you could use session to remember the values.

-- bruce (sqlworkcom)
"teo" <te*@inwind.itwrote in message
news:t7********************************@4ax.com...
>I have a Listbox,

if I set
EnableViewStarte = False
the
AutopostaBack fired by SelectedIndexChanged
doesn't work.
The 'SelectedIndexChanged' event should call
a sub called 'SayHalloPlease'.
Any Idea?

Here my simple code:
a Button
a Listbox
a Textbox

with Listbox EnableViewState = True it works
with Listbox EnableViewState = False it doesn't work

( AspNet 20 VisualStudio 2005 )

--- here the Code behind: ---------------------------------
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
MsgBox("I've been fired!")
SayHalloPlease(ListBox1.SelectedIndex)
End Sub

Private Sub SayHalloPlease(ByVal myNumber As Integer)
If myNumber = 2 Then TextBox1.Text = TextBox1.Text & "Hallo"
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.Items.Add("aaaaa")
ListBox1.Items.Add("bbbbb")
ListBox1.Items.Add("cccccThis")
ListBox1.Items.Add("ddddd")
ListBox1.Items.Add("eeeee")
End Sub
---- here the Asp code: -------------------------------------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
Style="z-index: 100; left: 284px; position: absolute; top:
40px">
</asp:ListBox>
&nbsp;
<asp:Button ID="Button1" runat="server" Style="z-index: 102; left:
164px; position: absolute;
top: 48px" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 104;
left: 472px; position: absolute;
top: 64px"></asp:TextBox>

</div>
</form>
</body>
</html>


Sep 28 '06 #2
teo
The fact is that

I have no problem to repopulate the listbox
before the page appear
(I have the data and I usually go in the Form1_Load event)

but

I need to store the index of the item
that the user selected,
because I want to restore it
after I repopulated the listbox

But I'm not able to detect the
moment/event/when
store it.
Obviously I need to store it
after the user clicked the item
and before the page disappears
Shortly
with EnableViewState = False
I'm able to repopulate the Listbox
but I'm not able to set the selected value
that the user clicked.



>if you turn off viewstate, then the control does not send the list of
dropdown values to the page. thus when the postback value is applied there
is no matching value in the list (as the control can not reconstruct it).

in the oninit of the postback after the click (before postback data is
applied) you need to re-add the list values added by the onclick of the
previous render. hint: you could use session to remember the values.

-- bruce (sqlworkcom)
"teo" <te*@inwind.itwrote in message
news:t7********************************@4ax.com.. .
>>I have a Listbox,

if I set
EnableViewStarte = False
the
AutopostaBack fired by SelectedIndexChanged
doesn't work.
The 'SelectedIndexChanged' event should call
a sub called 'SayHalloPlease'.
Any Idea?

Here my simple code:
a Button
a Listbox
a Textbox

with Listbox EnableViewState = True it works
with Listbox EnableViewState = False it doesn't work

( AspNet 20 VisualStudio 2005 )

--- here the Code behind: ---------------------------------
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
MsgBox("I've been fired!")
SayHalloPlease(ListBox1.SelectedIndex)
End Sub

Private Sub SayHalloPlease(ByVal myNumber As Integer)
If myNumber = 2 Then TextBox1.Text = TextBox1.Text & "Hallo"
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.Items.Add("aaaaa")
ListBox1.Items.Add("bbbbb")
ListBox1.Items.Add("cccccThis")
ListBox1.Items.Add("ddddd")
ListBox1.Items.Add("eeeee")
End Sub
---- here the Asp code: -------------------------------------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
Style="z-index: 100; left: 284px; position: absolute; top:
40px">
</asp:ListBox>
&nbsp;
<asp:Button ID="Button1" runat="server" Style="z-index: 102; left:
164px; position: absolute;
top: 48px" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 104;
left: 472px; position: absolute;
top: 64px"></asp:TextBox>

</div>
</form>
</body>
</html>

Sep 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by DC Gringo | last post: by
8 posts views Thread by Steve Schroeder | last post: by
4 posts views Thread by Nathan Sokalski | last post: by
9 posts views Thread by zdrakec | last post: by
6 posts views Thread by Peter | last post: by
15 posts views Thread by Doogie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.