malarashok
asked on
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.
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.
in javascript change event of the dropdownlist check the text and call the server function if needed
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
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
ASKER
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
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
ASKER
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(ev entTarget, eventArgument,ddlStateProv inceID)
{
var ddl = document.getElementById(ev entTarget)
// Canada = 32,
// Mexico = 119,
// UnitedStates = 190,
var ddlStateProvince = document.getElementById(dd lStateProv inceID)
//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="dd lCountry_S electedInd exChanged" />
File Name: Address.aspx.cs
Code :
//added client side java script to dropdown control.
ddlCountry.Attributes.Add( "onchange" , "javascript:CountrySelecte dPostBack( '" + ddlCountry.ClientID + "','','" + ddlStateProvince .ClientID + "');");
Thanks,
Ashokkumar M
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(ev
{
var ddl = document.getElementById(ev
// Canada = 32,
// Mexico = 119,
// UnitedStates = 190,
var ddlStateProvince = document.getElementById(dd
//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="dd
File Name: Address.aspx.cs
Code :
//added client side java script to dropdown control.
ddlCountry.Attributes.Add(
Thanks,
Ashokkumar M
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.