[Last Call] Learn how to a build a cloud-first strategyRegister Now


Partial post back for dropdown asp.net server control

Posted on 2007-07-23
Medium Priority
Last Modified: 2013-11-07
I have asp.net dropdown list, which has list of country.  On select of some of the dropdown item, it should post back.
For example I have United State, India countries in Dropdown list.
On select of United State page should postback and call on select method.
On select of India page should not postback.

Please let me know how to do it.
Question by:malarashok

Expert Comment

ID: 19546025
in javascript change event of the dropdownlist check the text and call the server function if needed
LVL 12

Expert Comment

ID: 19546100
if you have India selected default and you change to US it will posback
but when you have india selected default and you again select India it will not post back bcoz you are actually not changing the item..

To resolve this issue add a blank field as first item in the dropdown!!


Author Comment

ID: 19599664
hi Razo,
             javascript change event of the dropdownlist, may work. Programmatically how to post back for post back event  for dropdown select. you share code for java script for post back.

Ashokkumar M

Author Comment

ID: 19714983
razo & renjurdevan  Thank you for your effort . I have written code for my requirement. Since you have out some effort to find solution. I am sharing the code with you. Solution and code is given below.

·  Custom post back has been implemented for country Dropdown; by adding custom postback we can avoid unnecessary page refresh.
·  When user is selecting the country, Java script function will validates if our application has list of state of selected country then page will be postback and populate the state list in dropdown  

 if user selects Canada, Mexico or United States from country dropdown then  corresponding State will be poppulated, for other countries Dropdown will not be populated and not referesh(postback) the page.

File Name:   Address.aspx
<script type="text/javascript" language="javascript">
   function CountrySelectedPostBack(eventTarget, eventArgument,ddlStateProvinceID)
        var ddl = document.getElementById(eventTarget)
//        Canada = 32,
//        Mexico = 119,
//        UnitedStates = 190,
        var ddlStateProvince = document.getElementById(ddlStateProvinceID)
        //if the selected country is Canada , Mexico , UnitedState
        // or previous selected country is Canada , Mexico , UnitedState then
        //post back the page action
        if (ddl.value == "190" || ddl.value == "32" || ddl.value == "119"  || ddlStateProvince != null)
            __doPostBack(eventTarget, eventArgument);

//Auto postback is removed country dropdown list.
<asp:DropDownList ID="ddlCountry" runat="server" Width="306px" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged"  />

File Name:   Address.aspx.cs  
Code :
//added client side java script to dropdown control.
ddlCountry.Attributes.Add("onchange", "javascript:CountrySelectedPostBack('" + ddlCountry.ClientID + "','','" + ddlStateProvince .ClientID + "');");

Ashokkumar M


Accepted Solution

Computer101 earned 0 total points
ID: 20346024
PAQed with points refunded (50)

EE Admin

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

830 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