connectseekers.com

Monday, 5 January 2015

Validate DropDownlist Selected Value Using jQuery In Asp.net ,C#.Net

1/05/2015 - By Pranav Singh 0



This article will show you how you can validate the dropdown list selected value and if user select the proper value then redirect and get the selected value at server end using c#.net, jQuery in asp.net.



So for this article first we will create a new asp.net application and add the below code into the .asp page.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication1.WebForm4" %>

<!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>Validate DropDownlist Selected Value Using jQuery In Asp.net ,C#.Net</title>
    <script src="jquery-1.4.1.min.js" type="text/javascript"></script>
    <script language="javascript">
        function Validateddl() {
            var selectedValue = $("#<%=DropDownList1.ClientID %>").val();
            if (selectedValue == "0") {
                alert("Please select some item.");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      Select : <asp:DropDownList ID="DropDownList1" runat="server" Width="158px">
            <asp:ListItem Selected="True" Value="0">Select</asp:ListItem>
            <asp:ListItem Value="1">Item1</asp:ListItem>
            <asp:ListItem Value="2">Item2</asp:ListItem>
            <asp:ListItem Value="3">Item3</asp:ListItem>
            <asp:ListItem Value="4">Item4</asp:ListItem>
        </asp:DropDownList>
        <br /> <br />
        <asp:Button ID="Button1" runat="server" Text="Submit"
            OnClientClick="javascript:return Validateddl();" onclick="Button1_Click"/><br />
        <asp:Label ID="Label1" runat="server" style="color: #FF3300" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

In above code please check the jquery code

  <script src="jquery-1.4.1.min.js" type="text/javascript"></script>
    <script language="javascript">
        function Validateddl() {
            var selectedValue = $("#<%=DropDownList1.ClientID %>").val();
            if (selectedValue == "0") {
                alert("Please select some item.");
                return false;
            }
            return true;
        }
    </script>
                                                    
In above code first I have retrieve the selected value and after that I have check the selected value is allowed to access or not for postback. If it is allowed on that case we will we will return true and postback will take place.


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top