473,387 Members | 1,592 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,387 software developers and data experts.

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

Similar topics

1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
2
by: DC Gringo | last post by:
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the...
6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
8
by: Steve Schroeder | last post by:
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...
4
by: Nathan Sokalski | last post by:
I have a DataList that has an Button as one of the controls in it's ItemTemplate. The Button has a CommandName="delete" attribute, but when I click it the DeleteCommand event doesn't even get...
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
6
by: Peter | last post by:
ASP.NET 2.0 Visual Studio 2008 I have the following code and when the textbox displays and I press Enter while in the text box I get AutoPostBack, how do I stop AutoPostBack? TextBox txt =...
15
by: Doogie | last post by:
I have a .net app that a user currently enters a number in a text box, hits a button and a data call is executed. She wants the ability to enter in multiple numbers (up to 100). So to make...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.