Solved

.NET Combo box - post back on change

Posted on 2011-03-18
6
633 Views
Last Modified: 2012-05-11
Hi I think its pretty straight forward what im trying to do - for a  aspx web page to post back the results of a selected combo box , I can do this with a button on the form but I would like to post back when the user has selected an item in the combo box, Iv seen other solutions that use a javascript on chnange event within the combo box but cant quite see how it works. Any help would be great!  
.net code

 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
        Dim t As Integer
        For t = 1 To 12
            DropDownList1.Items.Add("test " & t)
        Next t
    End Sub
HTML code
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="KormaCom.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>WebForm1</title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<asp:dropdownlist id="DropDownList1" style="Z-INDEX: 101; LEFT: 152px; POSITION: absolute; TOP: 72px"
				runat="server" Height="32px" Width="224px"></asp:dropdownlist></form>
	</body>
</HTML>

Open in new window

0
Comment
Question by:MrDavidThorn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Accepted Solution

by:
jkofte earned 500 total points
ID: 35164262
you should set the autopostback property of combobox to true and in events, create the selected index changed event.
0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35164270
Set AutoPostback property of Combobox to true.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35164278
You want to post the seleted drop down value to next page or on same page button click ?

first of all you need to add postback condition in page_load
    Dim t As Integer
        If Page.IsPostBack = False Then
            For t = 1 To 12
                DropDownList1.Items.Add("test " & t)
            Next t
        End If

On same page on button click
  Response.Write(DropDownList1.SelectedItem.Value)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35164279
Do add If(!Ispostback) condition to your page load, so that combobox is loaded each time page postbacks.
0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35164280
Do add If(!Ispostback) condition to your page load, so that combobox is not loaded each time page postbacks.
0
 
LVL 10

Expert Comment

by:John Claes
ID: 35164342
to ensure that a dropdown selection Change triggers a postBack you should add the AutoPostback to true.

This ensures that every change will do a PostBack.

But knowing the standard use of page_Load you're filling there the dropdown.
So you should indeed use the ( Page.IsPostBack) property to check.
if this is false this is the initial call for the page and the controls must be initialised.

I hope this was clear and understandable ;-)

regards
poor beggar
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question