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
--
Derek Martin
593074Have you tried using .SelectedItem to see if you're getting the correct
text?
"Derek Martin" <dmj2195@.DONTSPAMMEokstateDOT.edu> wrote in message
news:OYCV9nHrEHA.376@.TK2MSFTNGP14.phx.gbl...
> 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
> --
> Derek Martin
> 593074
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
"i. Wiin" <iiwiin@.yagoo.com> wrote in message
news:%2370$7rHrEHA.3868@.TK2MSFTNGP15.phx.gbl...
> Have you tried using .SelectedItem to see if you're getting the correct
> text?
>
> "Derek Martin" <dmj2195@.DONTSPAMMEokstateDOT.edu> wrote in message
> news:OYCV9nHrEHA.376@.TK2MSFTNGP14.phx.gbl...
>> 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
>>
>> --
>> Derek Martin
>> 593074
>>
>>
Derek Martin wrote:
> 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
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
"Hans Kesting" <news.2.hansdk@.spamgourmet.com> wrote in message
news:eMF7TyHrEHA.1712@.tk2msftngp13.phx.gbl...
> Derek Martin wrote:
>> 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
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
"Hans Kesting" <news.2.hansdk@.spamgourmet.com> wrote in message
news:eMF7TyHrEHA.1712@.tk2msftngp13.phx.gbl...
> Derek Martin wrote:
>> 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
Derek Martin wrote:
> 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
> 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
>
>
> "Hans Kesting" <news.2.hansdk@.spamgourmet.com> wrote in message
> news:eMF7TyHrEHA.1712@.tk2msftngp13.phx.gbl...
>> Derek Martin wrote:
>>> 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
0 comments:
Post a Comment