Solved

.NET Combo box - post back on change

Posted on 2011-03-18
6
625 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
6 Comments
 
LVL 9

Accepted Solution

by:
jkofte earned 500 total points
Comment Utility
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
Comment Utility
Set AutoPostback property of Combobox to true.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 10

Expert Comment

by:Asim Nazir
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now