Partial post back for dropdown asp.net server control

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.
malarashokAsked:
Who is Participating?
 
Computer101Commented:
PAQed with points refunded (50)

Computer101
EE Admin
0
 
razoCommented:
in javascript change event of the dropdownlist check the text and call the server function if needed
0
 
renjurdevanCommented:
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!!

Regards
Renju
0
 
malarashokAuthor Commented:
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.

Thanks,
Ashokkumar M
0
 
malarashokAuthor Commented:
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.

Solution:
·  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.

Code:
 
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);
         }
   }        
</script>

 
//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 + "');");

 Thanks,
Ashokkumar M

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.