Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have put together a small form with 3 different DropDownLists. The items to each DropDownList is loaded programatically during the onLoad event.

 

One is ddlIDType (where the customer enters their ID Type),

One is ddlState (where the customer enters their home state), and

One is ddlYear (where the customer enters the year of their birth).

 

In my code, I gather the information as follows:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyList As New DropListData ' A class I have with all the states and years
ddlState.DataSource = MyList.StateList
ddlState.DataBind()
ddlYear.DataSource = MyList.YearList
ddlYear.DataBind()
With ddlIDType.Items
.Add("Driver's License")
.Add("Passport")
.Add("Alien Registration")
.Add("Govt. Employee")
.Add("Military")
End With 
End Sub

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim strCustomerInfo as String = ""

strCustomerInfo &= ddlIDType.SelectedItem.Text
strCustomerInfo &= ddlState.SelectedItem.Text
strCustomerInfo &= ddlYear.SelectedItem.Text
End Sub

The IDType field works the way it should, but State and Year do not. This leads me to believe that somehow my databinding is not working the way I want it to. The data shows up in each of the DropDownList when I run the webpage. When I click the btnSubmit button, State and Year consistantly return the topmost value, no matter which value was selected.

 

Could someone explain what is going on, and how I could correct this?

Posted

Thanks! I never knew the Page keyword was there.

 

I have another question that you may be able to help me with: On my form, when I click SUBMIT, the page reloads some of the time (but not all of the time). I put a breakpoint on the "Sub btnSUBMIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handels btnSUBMIT.Click", but even when I click the SUMBIT button, the debugger never goes to this sub - It goes straight to Page_Load.

 

What is this? Could you offer any solution(s) here?

  • Administrators
Posted
The internet is inherantly stateless, once the server has sent a page to the browser it no longer cares about the browser and the page is discarded. When you submit the page back to the server it has to recreate the page from fresh - including runnning all the page_init, page_load events before it will execute control events.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

FYI

 

You also may want to look into using a StringBuilder and the Append method. That way you aren't creating a new string each time you concatenate with the &.

Wanna-Be C# Superstar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...