|
 |
aspx thread: Viewstate not working for listboxes...
Message #1 by "Greg Quinn" <greg@i...> on Thu, 15 Aug 2002 09:14:34 -0700
|
|
I have two listbox controls on a page that are databound when the page loads
the first time, if the page is posted back, the controls are not rebound
again because the viewstate should keep the listbox information.
Well this is not happening, when I call a server-side function to read the
items sitting in the listbox, the listboxes reset to their original values,
even though I have checked for a postback.
What is happening here? this doesn't make sense...
Greg
Message #2 by "Joe Dip****" <joedip****@h...> on Thu, 15 Aug 2002 16:36:01 +0000
|
|
Are you by any chance dynamically creating the list box itself (not the
items)? If you recreate the list box dynamically, but do not rebind the
items, then you will loose your items.
Tobin Titus, MCSD
co-author:
VB.NET Threading Handbook
Wrox Press - ISBN: 1861007132
Coming Soon:
Beginning VB.NET Web Programming
Wrox Press - ISBN: 1861007361
From: "Greg Quinn" <greg@i...>
I have two listbox controls on a page that are databound when the page loads
the first time, if the page is posted back, the controls are not rebound
again because the viewstate should keep the listbox information.
Well this is not happening, when I call a server-side function to read the
items sitting in the listbox, the listboxes reset to their original values,
even though I have checked for a postback.
What is happening here? this doesn't make sense...
Greg
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
Message #3 by "Greg Quinn" <greg@i...> on Thu, 15 Aug 2002 19:00:55 -0700
|
|
No, the listboxes are coded into the html of the page.
Greg
-----Original Message-----
From: Joe Dip**** [mailto:joedip****@h...]
Sent: Thursday, August 15, 2002 9:36 AM
To: ASP+
Subject: [aspx] Re: Viewstate not working for listboxes...
Are you by any chance dynamically creating the list box itself (not the
items)? If you recreate the list box dynamically, but do not rebind the
items, then you will loose your items.
Tobin Titus, MCSD
co-author:
VB.NET Threading Handbook
Wrox Press - ISBN: 1861007132
Coming Soon:
Beginning VB.NET Web Programming
Wrox Press - ISBN: 1861007361
From: "Greg Quinn" <greg@i...>
I have two listbox controls on a page that are databound when the page loads
the first time, if the page is posted back, the controls are not rebound
again because the viewstate should keep the listbox information.
Well this is not happening, when I call a server-side function to read the
items sitting in the listbox, the listboxes reset to their original values,
even though I have checked for a postback.
What is happening here? this doesn't make sense...
Greg
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #4 by "Andrew Bradnan" <fudomyo@w...> on Thu, 15 Aug 2002 11:10:16 -0700
|
|
Are you checking the values in Page_Load? The view state in not loaded
here. You'll notice all the examples use a button or something to
generate an event (they come after page_load). See what you get in
Page_PreRender.
Hope that helps.
Fudo
-----Original Message-----
From: Greg Quinn [mailto:greg@i...]
Sent: Thursday, August 15, 2002 9:15 AM
To: ASP+
Subject: [aspx] Viewstate not working for listboxes...
I have two listbox controls on a page that are databound when the page
loads
the first time, if the page is posted back, the controls are not rebound
again because the viewstate should keep the listbox information.
Well this is not happening, when I call a server-side function to read
the
items sitting in the listbox, the listboxes reset to their original
values,
even though I have checked for a postback.
What is happening here? this doesn't make sense...
Greg
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=3D1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=3D1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #5 by "Ramanujam" <sramanuj@c...> on Tue, 20 Aug 2002 08:20:31
|
|
Well If did u check the viewstate property of the ListBox... see if thats
true.... Only then the values are maintained. and one more is that
postback property of the ListBox will only post to server on any click or
any code in server side... and they are not supposed to maintain any
values....
This should keep u going. In case probelem still exists.. mail me
cheers
S.Ramanujam
Programmer Analyst
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
: +xx xx xxx xxxx [Res]
> I have two listbox controls on a page that are databound when the page
loads
the first time, if the page is posted back, the controls are not rebound
again because the viewstate should keep the listbox information.
Well this is not happening, when I call a server-side function to read the
items sitting in the listbox, the listboxes reset to their original values,
even though I have checked for a postback.
What is happening here? this doesn't make sense...
Greg
Message #6 by "Greg Quinn" <greg@i...> on Tue, 20 Aug 2002 10:03:36 -0700
|
|
I have a;ready taken into account everything you have said, and yes I have
even explicitly enabled viewstate in the listbox tag, but still have the
same problem.
Please can someone help me with this!
Greg
-----Original Message-----
From: Ramanujam [mailto:sramanuj@c...]
Sent: Tuesday, August 20, 2002 8:21 AM
To: ASP+
Subject: [aspx] Re: Viewstate not working for listboxes...
Well If did u check the viewstate property of the ListBox... see if thats
true.... Only then the values are maintained. and one more is that
postback property of the ListBox will only post to server on any click or
any code in server side... and they are not supposed to maintain any
values....
This should keep u going. In case probelem still exists.. mail me
cheers
S.Ramanujam
Programmer Analyst
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
: +xx xx xxx xxxx [Res]
> I have two listbox controls on a page that are databound when the page
loads
the first time, if the page is posted back, the controls are not rebound
again because the viewstate should keep the listbox information.
Well this is not happening, when I call a server-side function to read the
items sitting in the listbox, the listboxes reset to their original values,
even though I have checked for a postback.
What is happening here? this doesn't make sense...
Greg
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #7 by "Sampath, Ramanujam (Cognizant)" <SRamanuj@c...> on Tue, 20 Aug 2002 13:41:37 +0530
|
|
Well greg... can u post the code u are using in the whole of the page... Let
me check it....
cheers
S.Ramanujam
Programmer Analyst
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
: +xx xx xxx xxxx [Res]
-----Original Message-----
From: Greg Quinn [mailto:greg@i...]
Sent: Tuesday, August 20, 2002 10:34 PM
To: ASP+
Subject: [aspx] Re: Viewstate not working for listboxes...
I have a;ready taken into account everything you have said, and yes I have
even explicitly enabled viewstate in the listbox tag, but still have the
same problem.
Please can someone help me with this!
Greg
-----Original Message-----
From: Ramanujam [mailto:sramanuj@c...]
Sent: Tuesday, August 20, 2002 8:21 AM
To: ASP+
Subject: [aspx] Re: Viewstate not working for listboxes...
Well If did u check the viewstate property of the ListBox... see if thats
true.... Only then the values are maintained. and one more is that
postback property of the ListBox will only post to server on any click or
any code in server side... and they are not supposed to maintain any
values....
This should keep u going. In case probelem still exists.. mail me
cheers
S.Ramanujam
Programmer Analyst
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
: +xx xx xxx xxxx [Res]
> I have two listbox controls on a page that are databound when the page
loads
the first time, if the page is posted back, the controls are not rebound
again because the viewstate should keep the listbox information.
Well this is not happening, when I call a server-side function to read the
items sitting in the listbox, the listboxes reset to their original values,
even though I have checked for a postback.
What is happening here? this doesn't make sense...
Greg
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
Message #8 by "Greg Quinn" <greg@i...> on Wed, 21 Aug 2002 14:47:04 -0700
|
|
What someone pointed out to me is that because I am using a client side
script to modify the listboxes, the viewstate is not being updated, and thus
I should not use the viewstate.
So I have tried disabling the viewstate, but when it comes submitting the
values to my function, it reverts back to what was in the viewstate still.
Please take a look at my code, note the source code for the .js file is
listed afterwards.
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
<%@ Page EnableViewState = False %>
<script language = "vb" runat = "server">
Sub Page_Load()
If NOT Page.IsPostBack Then
PopulateLists()
End If
End Sub
Sub PopulateLists()
' DataBind Left Menu
' We must first remove any leading and trailing commas so the sharelist is
readable by SQL...
Dim objConnection as New
SqlConnection(ConfigurationSettings.AppSettings("connString"))
Dim SqlGetList, shareListString, shareListCut as String
Dim shareListStringLength as Integer
SqlGetList = "SELECT TOP 1 ShareList FROM ContactsShareLookup
WHERE ContactID = " & Request.QueryString("ContactID")
Dim objCommand as New SqlCommand(SqlGetList, objConnection)
objConnection.Open
Dim objDataReaderGetList as SqlDataReader
objDataReaderGetList = objCommand.ExecuteReader()
If objDataReaderGetList.Read() = False Then
shareListString = "0"
Else
shareListString = objDataReaderGetList("shareList")
If Len(shareListString) <= 0 Then
shareListString = "0"
Else
shareListCut = Mid(shareListString, 1, 1)
if Instr(1, shareListCut, ",") Then
shareListStringLength = Len(shareListString)
shareListString = Mid(shareListString, 2, shareListStringLength - 1)
end if
End If
End If
objDataReaderGetList.Close()
objConnection.Close()
' Bind Left List
Dim SqlBindLeftList as String
SqlBindLeftList = "Select Users_UserID, (Users_Fname + char(32) +
Users_LName) as ExprJoinedName From Users WHERE Users_UserID <> " &
Session("UserID") & " AND Users_UserID NOT IN (" & shareListString & ")
ORDER BY Users_Fname"
objCommand = New SqlCommand(SqlBindLeftList, objConnection)
objConnection.Open
Dim objDataReaderBindLeftList as SqlDataReader
objDataReaderBindLeftList = objCommand.ExecuteReader()
list1.DataSource = objDataReaderBindLeftList
list1.DataBind()
objDataReaderBindLeftList.Close()
objConnection.Close()
' Bind Right List
Dim SqlBindRightList as String
SqlBindRightList = "Select Users_UserID, (Users_Fname + char(32) +
Users_LName) as ExprJoinedName From Users WHERE Users_UserID <> " &
Session("UserID") & " AND Users_UserID IN (" & shareListString & ") ORDER BY
Users_Fname"
objCommand = New SqlCommand(SqlBindRightList, objConnection)
objConnection.Open
Dim objDataReaderBindRightList as SqlDataReader
objDataReaderBindRightList = objCommand.ExecuteReader()
list2.DataSource = objDataReaderBindRightList
list2.DataBind()
objDataReaderBindRightList.Close()
objConnection.Close()
End Sub
Sub UpdateShare(Sender as Object, E as EventArgs)
' Update share list for contact
Dim objConnection = New
SQLConnection(ConfigurationSettings.AppSettings("connString"))
' First delete existing record
Dim strSQLDeleteExistingShare as String
strSQLDeleteExistingShare = "Delete From ContactsShareLookup WHERE
ContactID = " & Request.QueryString("ContactID") & " AND UserID = " &
Session("UserID")
Dim myCommandShareDelete as New SQLCommand(strSQLDeleteExistingShare,
objConnection)
myCommandShareDelete.Connection.Open()
myCommandShareDelete.ExecuteNonQuery()
myCommandShareDelete.Connection.Close()
' Add new share information to ContactsShareLookup
Dim newIDConstructor as new NextIDClass
Dim newShareID as Integer
newShareID = newIDConstructor.Get_Next_ID("ContactsShareLookup",
"ContactsShareID")
Dim shareString as String
Dim validItems as Integer
For validItems = 0 to list2.Items.Count() - 1
shareString += "," & list2.items(validItems).Value
Next
Dim strSQLInsertShare as String
strSQLInsertShare = "INSERT INTO ContactsShareLookup (ContactsShareID,
UserID, ContactID, ShareList) VALUES "
strSQLInsertShare += "(" & newShareID & ","
strSQLInsertShare += "" & Session("UserID") & ","
strSQLInsertShare += "" & Request.QueryString("ContactID") & ","
strSQLInsertShare += "'" & shareString & "')"
Dim myCommandShareInsert as New SQLCommand(strSQLInsertShare,
objConnection)
myCommandShareInsert.Connection.Open()
myCommandShareInsert.ExecuteNonQuery()
myCommandShareInsert.Connection.Close()
lblMessage.Text = shareString
End Sub
</script>
<HEAD>
<title>Officium</title>
<SCRIPT LANGUAGE="JavaScript" src = "../scripts/boxes.js"></script>
<link href="../include/forms.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY bgcolor="#FFFFFF">
<asp:label id = "lblMessage" runat = "server" />
<form id="shareForm" runat = "server">
<table>
<tr>
<td colspan="3">Select the users to share this item with...</td>
</tr>
<tr>
<td> </td>
<td align="center" valign="middle"> </td>
<td> </td>
</tr>
<tr>
<td>
<asp:listbox enableViewState = "false" id = "list1" Style
"width:200px;height:350px;" DataValueField = "Users_UserID" DataTextField
"ExprJoinedName" cssStyle = "width : 150px" selectionMode = "multiple" runat
= "server" />
</td>
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.list2,this.form.list1)"
value="<<">
<input type="button" onClick="move(this.form.list1,this.form.list2)"
value=">>">
</td>
<td>
<asp:listbox enableViewState = "false" id = "list2" Style
"width:200px;height:350px;" DataValueField = "Users_UserID" DataTextField
"ExprJoinedName" cssStyle = "width : 150px" selectionMode = "multiple" runat
= "server" />
</td>
</tr>
<tr>
<td> </td>
<td align="center" valign="middle">
<asp:button id = "updateBut" Text = "Save" onClick = "UpdateShare"
runat = "server" />
</td>
<td> </td>
</tr>
</table>
</form>
</body>
Here is the source for boxes.js
-------------------------------
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
}
-----Original Message-----
From: Sampath, Ramanujam (Cognizant) [mailto:SRamanuj@c...]
Sent: Tuesday, August 20, 2002 1:12 AM
To: ASP+
Subject: [aspx] Re: Viewstate not working for listboxes...
Well greg... can u post the code u are using in the whole of the page... Let
me check it....
cheers
S.Ramanujam
Programmer Analyst
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
: +xx xx xxx xxxx [Res]
-----Original Message-----
From: Greg Quinn [mailto:greg@i...]
Sent: Tuesday, August 20, 2002 10:34 PM
To: ASP+
Subject: [aspx] Re: Viewstate not working for listboxes...
I have a;ready taken into account everything you have said, and yes I have
even explicitly enabled viewstate in the listbox tag, but still have the
same problem.
Please can someone help me with this!
Greg
-----Original Message-----
From: Ramanujam [mailto:sramanuj@c...]
Sent: Tuesday, August 20, 2002 8:21 AM
To: ASP+
Subject: [aspx] Re: Viewstate not working for listboxes...
Well If did u check the viewstate property of the ListBox... see if thats
true.... Only then the values are maintained. and one more is that
postback property of the ListBox will only post to server on any click or
any code in server side... and they are not supposed to maintain any
values....
This should keep u going. In case probelem still exists.. mail me
cheers
S.Ramanujam
Programmer Analyst
38 & 39 Whites Road,
WCB - Whites Road Circular Building
Royapettah, Chennai - 600014
Ph : +xx xx xxx xxxx Extn 5113 [Off]
: +xx xx xxx xxxx [Res]
> I have two listbox controls on a page that are databound when the page
loads
the first time, if the page is posted back, the controls are not rebound
again because the viewstate should keep the listbox information.
Well this is not happening, when I call a server-side function to read the
items sitting in the listbox, the listboxes reset to their original values,
even though I have checked for a postback.
What is happening here? this doesn't make sense...
Greg
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
|
|
 |