Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi guys,

in my asp.net project,

I have added some code for 'Confirmation on Dropdowlist'

Mycode:
<asp:DropDownList ID="ddlCompleted" runat="server" Width="70px" AutoPostBack="true"
                                                    CausesValidation="true" ValidationGroup="complete" OnSelectedIndexChanged="SelectedIndexChanged">
                                                    <asp:ListItem Value="0" Text="No"></asp:ListItem>
                                                    <asp:ListItem Value="1" Text="Yes"></asp:ListItem>
                                                </asp:DropDownList>
                                                <script type="text/javascript">
                                                    function ConfirmDropDownValueChange(source, arguments) {
                                                        arguments.IsValid = confirm("Once the Job: Completed, it Can't be Edit or Delete!");
                                                    }
                                                </script>
                                                <asp:CustomValidator ID="ConfirmationCumstomValidator" runat="server"
                                                 ClientValidationFunction="ConfirmDropDownValueChange" Display="Dynamic" 
                                                 ValidationGroup="complete" />


the problem here is,
on the confirmation message,
if i click on 'cancel' it is making the ddl on 'yes' instead of 'no'.

the logic is as: on the confirmation message box,
if i click on 'ok' then the ddl should be 'yes'
if i click on 'cancel' then the ddl should be 'no'[i mean, no changes in the ddl index]

can anyone plz help me.

Thanks
Posted

use some javascript like...
function handleChange(opt) {
if (!confirm('are you sure')) {
JavaScript

opt.selectedIndex = opt.oldIndex;
}
else {
__doPostBack('YourDropDown','')
}
}
and set the client side events like so....

this.YourDropDown.Attributes["onChange"] = "handleChange(this)";
this.YourDropDown.Attributes["onFocus"] = "this.oldIndex = this.selectedIndex";
 
Share this answer
 
replace your code with below code it will work,

problem is you need to set EnableViewState property to true.


XML
<asp:DropDownList ID="ddlCompleted" runat="server" Width="70px" AutoPostBack="true" EnableViewState="true"
                                                    CausesValidation="true" ValidationGroup="complete" OnSelectedIndexChanged="SelectedIndexChanged">
                                                    <asp:ListItem Value="0" Text="No"></asp:ListItem>
                                                    <asp:ListItem Value="1" Text="Yes"></asp:ListItem>
                                                </asp:DropDownList>
                                                <script type="text/javascript">
                                                    function ConfirmDropDownValueChange(source, arguments) {
                                                        arguments.IsValid = confirm("Once the Job: Completed, it Can't be Edit or Delete!");
                                                    }
                                                </script>
                                                <asp:CustomValidator ID="ConfirmationCumstomValidator" runat="server"
                                                 ClientValidationFunction="ConfirmDropDownValueChange" Display="Dynamic"
                                                 ValidationGroup="complete" />
 
Share this answer
 
Comments
abdul subhan mohammed 7-Aug-14 16:50pm    
still its not working!!
ClimerChinna 8-Aug-14 0:23am    
could you send me selectedindex changed event code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900