Partial post back for dropdown server control

Posted on 2007-07-23
Last Modified: 2013-11-07
I have 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
    LVL 8

    Expert Comment

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

    Expert Comment

    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

    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

    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

    LVL 1

    Accepted Solution

    PAQed with points refunded (50)

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now