Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6226507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:02:34+00:00 2026-05-24T09:02:34+00:00

I am developing a VB.NET ASPX file in VS 2008. I am having trouble

  • 0

I am developing a VB.NET ASPX file in VS 2008. I am having trouble retrieving the selected input parameters however. This is real simple problem. Here is my current code:

<html>
    <SCRIPT LANGUAGE="VB" RUNAT="Server">
        Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

            If Not IsPostBack Then
                Main()
            Else
                Main2()
                If part_transfer.Value.Trim() <> "" Then
                    ShowChart()
                    Panel1.Visible = False
                    Panel2.Visible = True
                End If
            End If

        End Sub

Sub Main() 
'*** Query database and get arrays for the chart and bind query results to datagrid  

Dim YearDate As Date = "1/1/2010"
Dim arrYear As New ArrayList()
While YearDate <= Today
arrYear.Add(YearDate.ToString("yyyy"))
YearDate = YearDate.AddYears(1)
End While

dYear.DataSource = arrYear
dYear.DataBind()
dYear.SelectedValue = Today.ToString("yyyy")

Dim ListMonth As Date = "1/1/2010"
Dim arrListMonth As New ArrayList()
While ListMonth <= "12/1/2010"
arrListMonth.Add(ListMonth.ToString("MMM"))
ListMonth = ListMonth.AddMonths(1)
End While

dEndMonth.DataSource = arrListMonth
dEndMonth.DataBind()

dEndMonth.SelectedValue = Today.ToString("MMM")

Response.Write("Main " & dEndMonth.SelectedValue & "<br>")...
        End Sub

        Sub Main2()
        '*** Query database and get arrays for the chart and bind query results to datagrid  
            Dim YearDate As Date = "1/1/2010"
            Dim arrYear As New ArrayList()

            Dim TextSearch As String 
            TextSearch = dTextSearch.Text

            While YearDate <= Today
                arrYear.Add(YearDate.ToString("yyyy"))
                YearDate = YearDate.AddYears(1)
            End While

            dYear.DataSource = arrYear
            dYear.DataBind()

            Dim ListMonth As Date = "1/1/2010"
            Dim arrListMonth As New ArrayList()
            While ListMonth <= "12/1/2010"
                arrListMonth.Add(ListMonth.ToString("MMM"))
                ListMonth = ListMonth.AddMonths(1)
            End While

            dEndMonth.DataSource = arrListMonth
            dEndMonth.DataBind()

            Response.Write("Main2 " & dEndMonth.SelectedValue & "<br>")
...
        <form runat="Server" method="post" id="Form1">
            <div style="font-size:18pt; font-family:verdana; font-weight:bold; color:#336699">
               Parts Watch List
            </div>
            <br />
             <br />
                    <table>
                <tr><th>Year</th><th>Ending Month</th></tr>
                <tr>
                    <td><ASP:DROPDOWNLIST id="dYear" runat="Server" autopostback="true" /></td>
                    <td><ASP:DROPDOWNLIST id="dEndMonth" runat="Server" autopostback="true" width="75"/></td>
                    <td><ASP:TEXTBOX id="dTextSearch" OnTextChanged="dBtn_TextChanged" columns="2" MaxLength="30" Text="" runat="Server" autopostback="true" Width="150" /></td>
                    <td><ASP:BUTTON id="dBtn" Text="Search" OnClick="dBtn_Click" runat="Server" autopostback="true" width="100"/></td>
                </tr>
            </table>

…This is a really basic question. This code currently sets the dropdownlist like I want, but just doesn’t return selected month and year. How can I fix this?Note that Main2 sub is for PostBack = True.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:02:38+00:00Added an answer on May 24, 2026 at 9:02 am

    You are binding the DropDownList also in Main2(in PostBack). That prevents events from being triggered and overwrites the SelectedValue.

    If you would look for dEndMonth.SelectedValue before you DataBind it again, you would see that the SelectedValue is correct.

    Why aren’t you using an event-handler for the SelectedIndexChanged-Event of the DropDownList instead of your Main2-method?

    <ASP:DropDownList id="dEndMonth" OnSelectedIndexChanged="EndMonthChanged" autopostback="true" runat="Server" width="75"/></td>
    

    and in codebehind:

    Protected Sub EndMonthChanged(sender as Object, e as EventArgs)
        Dim dEndMonth = DirectCast(sender, DropDownList)
        'get selected value etc. and DataBind it AFTERWARDS when needed or whatever...'
    End Sub
    

    You should react on the user’s action and not on what you think what the user could have done, therefore use event-handlers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a C# / ASP.NET web application in VS 2008 on a
I am developing a C# VS 2008 / SQL Server 2008 ASP.NET Web Applications
I am developing a C#/SQL ASP.NET web application in VS 2008. Currently I am
I'm developing an ASP.NET application with C# and Visual Studio 2008 SP1. I'm using
I'm developing an ASP.NET 3.5 application with Visual Studio 2008. My default page has
Developing a .NET WinForms application: how can I check if the window is in
I developing ASP.NET application using a Swedish version of Windows XP and Visual studio
When developing with .NET 3.5 I naturally use LINQ for data access. But for
We are developing a .NET 2.0 winform application. The application needs to access Web
I am developing a .NET CF based Graphics Application, my project involves a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.