472,801 Members | 1,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,801 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 2855
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.