Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

.NET Combo box - post back on change

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
MrDavidThorn
Asked:
MrDavidThorn
1 Solution
 
jkofteCommented:
you should set the autopostback property of combobox to true and in events, create the selected index changed event.
0
 
Asim NazirCommented:
Set AutoPostback property of Combobox to true.
0
 
Pratima PharandeCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Asim NazirCommented:
Do add If(!Ispostback) condition to your page load, so that combobox is loaded each time page postbacks.
0
 
Asim NazirCommented:
Do add If(!Ispostback) condition to your page load, so that combobox is not loaded each time page postbacks.
0
 
John ClaesCommented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now