0

There are some questions on the stack about this but none helped me. This is my scenario. I have a drop down box

<asp:DropDownList ID="ddl" runat="server" DataTextField="ValText" DataValueField="ValID" AutoPostBack="true"  OnSelectedIndexChanged="ddl_SelectedIndexChanged"></asp:DropDownList>

Requirement:

When the drop down is selected or if the value is changed in the drop down I need a javascript alert asking whether the file selected in the drop down is to be downloaded. If the user clicks yes then the function for file to download should be invoked else nothing should be done. I don't have an Idea how to achieve this. Any suggestions?

Sam Daniel
  • 141
  • 1
  • 3
  • 17
  • Possible duplicate of https://stackoverflow.com/questions/20028858/asp-net-button-onclientclick-return-function-vs-onclientclick-function – Jay Buckman Dec 06 '17 at 11:55
  • 1
    I said it did not work. Kindly read my description properly first. And https://stackoverflow.com/questions/20028858/asp-net-button-onclientclick-return-function-vs-onclientclick-function is not at all what I need – Sam Daniel Dec 06 '17 at 11:55

1 Answers1

0

You can add onchange="javascript:validateSelection();" so it would look like this: <asp:DropDownList ID="ddl" onchange="javascript:validateSelection();" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged">

add then a javascript function using the 'confirm' popup like below:

function validateSelection() {
            var test = confirm("Would you like to download the file selected?");
            if (test)
            {
                __doPostBack("ctl00$MainContent$ddl1", "ddlchange");
            }
        }
Gary B
  • 61
  • 5