Simple (I Think!) Question

D

Derek Martin

I am new to ASP.NET but fairly good at VB.Net. I have an ASP.Net web
project going (VB.Net as the codebehind). I have created a page that I
dropped a DropDownList and a button on. I populated the dropdown list in
the Mybase.Load with some strings. When I click the button, I need to get
the .SelectedIndex property from the drop down list and give that number to
another method that does some stuff (gets a value out of an ArrayList based
on the selected index of the drop down in case you are interested).

My problem is that no matter what I select, when I push that button, I get
index(0) every time! Can someone show me the light?

Thanks,
Derek
 
D

Derek Martin

Thanks for your reply - I stuck another button on the page to do just that
and it in fact is not getting the correct text, always the first item
listed, no matter which I pick. Here is a code sample:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
infolabel1.Text = orgcombobox.SelectedItem.ToString
End Sub

Above ALWAYS returns item(0) :-(

Any ideas?

Derek
 
H

Hans Kesting

Derek said:
I am new to ASP.NET but fairly good at VB.Net. I have an ASP.Net web
project going (VB.Net as the codebehind). I have created a page that
I dropped a DropDownList and a button on. I populated the dropdown
list in the Mybase.Load with some strings. When I click the button,
I need to get the .SelectedIndex property from the drop down list and
give that number to another method that does some stuff (gets a value
out of an ArrayList based on the selected index of the drop down in
case you are interested).
My problem is that no matter what I select, when I push that button,
I get index(0) every time! Can someone show me the light?

Thanks,
Derek

Are you maybe setting that SelectedIndex in the Page_Load? This method
is called every time the page is accessed on the server (every postback).
You might want to guard it with a test for IsPostBack, so that it is executed
only the first time.

Hans Kesting
 
D

Derek Martin

Created a test page and that did work - if page.ispostback = false
(thanks!), now that brings up another question... I have a few class level
variables. On the post back, will it retain those from the previous screen
or will I need to reload them?

Here is some code example:

'Will these retain any values on a postback?
Dim thisperson As Object
Dim thisUserID As String
Dim thisMemberShip As ArrayList
Dim theseorgs As ArrayList
Dim theserequests As ArrayList

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Request.Cookies("CLUEAPP_WFID") Is Nothing Then
Response.Redirect("login.aspx")
Else
If Page.IsPostBack = False Then
thisUserID = Request.Cookies("CLUEAPP_WFID").Value
thisperson = CLUE.CLUE.profileinfo.getMETAinfo(thisUserID)
thisMemberShip = CLUE.CLUE.membershipinfo.getmembership(False,
thisUserID)
loadrequestbox()
loadchecklistbox()
loadpendingrequests()
End If
End If
End Sub
 
D

Derek Martin

Actually, here is a breakdown of some exact code I am trying to do:

Public Class testing
Inherits System.Web.UI.Page
#Removed Region Stuff

Dim theseorgs As ArrayList

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Page.IsPostBack = False Then
DropDownList1.Items.Clear()
Dim count As Integer
theseorgs = getstuff.orgsinfo.getorgs("Active", True) 'RETRUNS 2
OBJECTS
For count = 0 To theseorgs.Count - 1
DropDownList1.Items.Add(theseorgs(count).orgname) 'ADDS THE
2 NAMES INTO THE DROPDOWNLIST
Next
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label1.Text = theseorgs(DropDownList1.SelectedIndex).orgdata 'THIS
IS A STRING OF THIS OBJECT
End Sub
End Class

This is returning null reference exception.
???

Derek
 
H

Hans Kesting

Derek said:
Created a test page and that did work - if page.ispostback = false
(thanks!), now that brings up another question... I have a few class
level variables. On the post back, will it retain those from the
previous screen or will I need to reload them?

You *will* need to reload them. Maybe it's possible to save them in ViewState,
but beware:
- you can't save everything there (it needs to be "serializable")
- remember that viewstate will be sent to the browser and back again to the server

Hans Kesting
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top