Decrease Font Size
Increase Font Size
   BLOG

ASP-NET Confirm dialog box based on DropDownList selected value

ASP.NET Confirm dialog box based DropDownList selected value

ASP.NET JavaScript popup window basedon DropDownList selected value

Popup confirmation before ASP.NET Form Submit |

Add a JavaScript popup to an ASP.NET button |

Display Confirmation pop up window |

ASP.NET DropDownList Confirmation |

ASP.NET Adding JavaScript confirm to button based on DropDownList selected value |

Show JavaScript confirm message if DropDownList selected value equal

 

Requirement

User want to see a popup confirmation dialog box on LinkButton click, only if the DropDownList.SelectedValue == ?


See example below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:DropDownList runat="server" ID="ddlTest">
        <asp:ListItem Selected="True">select</asp:ListItem>
        <asp:ListItem>a</asp:ListItem>
        <asp:ListItem>b</asp:ListItem>
        <asp:ListItem>c</asp:ListItem>
        <asp:ListItem>d</asp:ListItem>
        <asp:ListItem>e</asp:ListItem>   
    </asp:DropDownList>
    
    <asp:LinkButton ID="IsertButton"
                  runat="server"
                  Text="Insert" onclick="IsertButton_Click"
                  OnClientClick="return CheckIfZeroSelected();" />
   
    </div>
    </form>
    
  <script type="text/javascript">
      function Insert_Confirmation() {
          if (confirm("Are you certain that you want to insert with selected value 0?"))
              return true; else return false;
      }

      function CheckIfZeroSelected() {
          var selObj = document.getElementById('<%= ddlTest.ClientID %>');

          if (selObj.selectedIndex === 0) {
              return Insert_Confirmation();
          }    
      }
  </script>  
</body>
</html>

Comments (12) -

  • Catering Sydney

    1/19/2010 11:54:53 AM |

    Good post...this is by far the best code I've seen on this topic on the internet.I really like to personally thank you and I look forward to reading your blog more and more..I love to visit her very often.....

  • ripped abs

    1/30/2010 6:26:44 PM |

    I hope your blog and articles will keep on putting me on the right direction as long as possible! Thanks ---

  • leslie

    1/30/2010 8:43:05 PM |

    Great code. many thanks.

  • cheap hotels in las vegas

    2/1/2010 9:46:47 PM |

    Hai friends, I want to display a confirm messagbox with "ok" and "cancel" button. when i click ok it has to call a procedure to do deletion.

  • df

    2/2/2010 12:40:08 PM |

    hi..

  • Acid Reflux Symptoms

    2/7/2010 5:17:41 AM |

    I was very pleased to find this site. Thanks for this great read!  I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

  • Abogado Laborista

    2/14/2010 1:46:24 PM |

    Hi from Russia! Will it be possible for me to quote a post as part of your weblog with the link to you? I've tried emailing you regarding this problem but it appears i cant achieve you, please reply when have a moment, thanks.

  • laser pointer

    2/15/2010 2:53:23 AM |

    nice post.

  • indonesia java international destination

    2/25/2010 12:35:52 PM |

    you put the all great things which makes all people getting interested. but yes thats right, i agree. all you mention is make a sense. thanks

  • mobile banking software

    3/8/2010 7:11:39 AM |

    This is really such an interesting and very knowledgeable post here you have submitted so that i think i like it very much. I think it can be very beneficial for most of the people.

  • William

    3/16/2010 1:36:29 AM |

    I've been trying to find a good forum on asp.net dropdownlist confirmation and related material. Thanks for putting this up.
    Take care

  • Lorrie Guion

    4/27/2010 5:33:14 AM |

    great code helped me a lot since i am just beginning....
    i will be following up on your blog soon!

Add comment

Loading