[LISTBOX] AutoPostBack not fired with EnableViewState = False

T

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>
 
B

bruce barker \(sqlwork.com\)

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)
 
T

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.
 

Ask a Question

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

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

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top