Confirmation of delete for a drop down..
Hello All,
I have a problem in a project i am doing. Can any1 please help me in this.
I have a drop down list as follows :
Code:
<asp:DropDownList ID="PostActionDDL" runat="server" EnableViewState="false" OnSelectedIndexChanged="activeRegistrant_SelectedIndexChanged"
AutoPostBack="true" >
<asp:ListItem Value="0">Select an Action</asp:ListItem>
<asp:ListItem Value="1">View</asp:ListItem>
<asp:ListItem Value="2">Delete</asp:ListItem>
</asp:DropDownList>
And i have the C# code as follows :
Code:
protected void activeRegistrant_SelectedIndexChanged(object sender, EventArgs e)
{
///Some code..
int selectedAction = Convert.ToInt32(dropList.SelectedValue);
switch ((RegistrationActions)selectedAction)
{
case RegistrationActions.View:
Response.Redirect("RegistrantDetails.aspx?id=" + registrationId.ToString());
break;
case RegistrationActions.Delete:
DeleteRegistration(registrationId);
//some code...
break;
}
}
Now, everything here is fine and working. But now, if the user selects delete, the data is getting deleted correctly. But without any confirmation. So, if a user selects the delete in the drop down list, i want a pop up to ask " Are you sure you want to delete ?"
And, if the user clicks view, i don't need any pop up.
Can any1 please help me...
Thanks
Re: Confirmation of delete for a drop down..
You need to assign a javascript for your and show a confirm and return that result from your script.
If the user then clicks no/cancel - false is returned and the event is not send to the server.
So I would guess something like this in your code behind would work ( - although it might need some tinkering, this is off the top of my head)
Code:
PostActionDDL.Attributes.Add("onChange", "return confirm('Are you sure?');");
or add it in your markup
Re: Confirmation of delete for a drop down..
not Agreed,
this will cause the the confirm appear even if the user didn't chose the delete
so you need OnChange as Alsvha said,
but you need actually to call a JavaScript function
and chick the value of the DropDownList if it was Delete Show the Confirm
Re: Confirmation of delete for a drop down..
Quote:
Originally Posted by
avrail
not Agreed,
this will cause the the confirm appear even if the user didn't chose the delete
so you need OnChange as Alsvha said,
but you need actually to call a JavaScript function
and chick the value of the DropDownList if it was Delete Show the Confirm
Same systematic, and you can just add the drop down check into the onChange return statement.
Re: Confirmation of delete for a drop down..
Quote:
Originally Posted by
Alsvha
Same systematic, and you can just add the drop down check into the onChange return statement.
great,