Solved

.NET Combo box - post back on change

Posted on 2011-03-18
6
630 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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