Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2006, 04:24 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If it is single select only use the SelectedIndexChanged property to call your server side method.

"The one language all programmers understand is profanity."
 
Old July 27th, 2006, 03:04 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

     I tried Session way:
On Page_Load():
Dim temp1 As String
 temp1 = Session("ListBoxText")
  If CInt(temp1) <> -1 Then
    lbCurrentItems.SelectedIndex = CInt(temp1)
  End If

Private Sub listbox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listbox1.SelectedIndexChanged

Session("ListBoxText") = listbox1.SelectedIndex
End Sub

But it is always giving error,i have tried so many ways:

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.
Stack Trace:


[FormatException: Input string was not in a correct format.]
   Microsoft.VisualBasic.CompilerServices.DoubleType. Parse(String Value, NumberFormatInfo NumberFormat)
   Microsoft.VisualBasic.CompilerServices.DoubleType. Parse(String Value)
   Microsoft.VisualBasic.CompilerServices.IntegerType .FromString(String Value)

[InvalidCastException: Cast from string "" to type 'Integer' is not valid.]
   Microsoft.VisualBasic.CompilerServices.IntegerType .FromString(String Value)

Any idea?

Regards
Monica

 
Old July 27th, 2006, 03:53 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Try this on your page load:

Dim temp1 as integer = Session("listboxtext")

If Not temp1 is Nothing AND temp1 <> -1 then
[execute if]
End if

In your listbox sub:

If listbox1.selectedIndex > -1 then
 Session("ListBoxText") = listbox1.SelectedIndex
Else
 Session("ListBoxText") = -1
End If


"The one language all programmers understand is profanity."
 
Old July 27th, 2006, 04:17 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No effect. It is giving same error, infact earlier i had tried a slight variation of what you posted but it also met the same fate.

 
Old July 27th, 2006, 05:59 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok try this:

Dim temp1 as integer = CINT(Session("listboxtext")) 'If the session variable is empty this will cast the session variable to the value of 0

or

if not Session("listboxText") is nothing then
temp1 = session("listboxtext")
end if

The above essentially checks to see if the Session variable is Null and if it isnt it will set temp1 to the value of the session variable.

"The one language all programmers understand is profanity."
 
Old July 28th, 2006, 11:32 AM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

    Its hard time again. Same error. I believe in listbox1_SelectedIndexChanged all is well. I am unsure about the code what i am using in Page_Load(). Am i doing it right in Page_Load() to retrieve the session variable?

Regards
Monica

 
Old July 28th, 2006, 11:52 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The code I supplied in the previous post should go inside your Page_Load(). What happens is, when you navigate to that page for the very first time Session("listBoxText") will be null, it wont have a value assoicated with it. What you should do in your page load method is this:

Sub Page_Load()

If Not Page.IsPostBack then
if not Session("listboxText") is nothing then
  temp1 = session("listboxtext")
  lbCurrentItems.SelectedIndex = temp1
end if
End If

End Sub

hth

"The one language all programmers understand is profanity."
 
Old July 28th, 2006, 03:30 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Its done. The culprit was putting that code on Page_Load(). I put it where the data access is done & it worked. Thanks a lot for all your help.

Regards
Monica

 
Old July 28th, 2006, 03:31 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No worries, glad it worked out for you in the end.

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Postback problem dbrook007 ASP.NET 2.0 Professional 3 May 8th, 2008 01:02 AM
Postback Problem dbrook007 ASP.NET 2.0 Professional 1 April 1st, 2008 06:16 AM
Listbox,Postback and Datasource nichola_x_rose ASP.NET 1.0 and 1.1 Basics 5 March 22nd, 2007 04:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.