zintech
asked on
Javascript confirm window in C# code behind
I realize that a Javascript confirm() box can be accomplished in the following way:
<asp:button ID="AddRecordbutton" runat="server" Text="Add Record" onclick="AddRecordButton_C lick" onclientclick="return confirm('add record?');" />
However, I have a dropdownlist with 4 possible options, and when the user clicks a button I have to perform the action selected in the dropdownlist, only if one of the items in the dropdownlist is selected would I like to display a confirm message, not all of the time. I did a lot of searching and trial and error but can't seem to figure out how to accomplish this.
<asp:button ID="AddRecordbutton" runat="server" Text="Add Record" onclick="AddRecordButton_C
However, I have a dropdownlist with 4 possible options, and when the user clicks a button I have to perform the action selected in the dropdownlist, only if one of the items in the dropdownlist is selected would I like to display a confirm message, not all of the time. I did a lot of searching and trial and error but can't seem to figure out how to accomplish this.
Use this function in client click, with JQuery in your client side:-
OnClientClick="return Validate()";
function Validate()
{
if($('#ddlList').val() == "YourValue")
{
return confirm("Are you Sure?");
}
else
{
return true;
}
}
ASKER
I understand this solution you are proposing. However, I only want the confirm box to show if only one of the four dropdownlist options are selected. Your proposed solution would display the pop up box every time, when any option is selected
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It appears to me that the method Validate() is not being reached or properly called. In the else() part of the if statement, I also did a confirm() alert box to make sure the method is being reached and it is not
ASKER
I got it working. Thank you
ASKER
else if (DropDownList4.SelectedInd
{
ClientScript.RegisterClien
//Execute code
}