Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i do,my confusion is at which control's event i can check condition that all required fields are filled or not???
here we don't which control will be filled by user just before submit button.

please give me suggestion
Posted
Updated 17-Apr-14 22:59pm
v2

XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Disable Button</title>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js" ></script>
    <script type="text/javascript">

    $(document).ready(function (){
    validate();
    $('#txtName, #txtAddress, #txtPhone').change(validate);
});

function validate(){
    if ($('#txtName').val().length   >   0   &&
        $('#txtAddress').val().length  >   0   &&
        $('#txtPhone').val().length    >   0) {
        $("#btnClick").prop("disabled", false);
    }
    else {
        $("#btnClick").prop("disabled", true);
    }
}

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Name:"></asp:Label>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
        <br />
        <asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Address"></asp:Label>
        <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox><br />
        <br />
        <asp:Label ID="Label3" runat="server" Font-Bold="True" Text="Phone:"></asp:Label>
        <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox><br />
        <br />
        <asp:Button ID="btnClick" runat="server" OnClick="Button1_Click" Text="Submit" /></div>
    </form>
</body>
</html>
 
Share this answer
 
It's pretty simple.If the last control before submit button is TextBox use TextChanged Event[^] or if it is DropdownList use SelectedIndexChanged event

Check whether all the controls are filled in IF condition in the events .When all fields are filled ,then enable the submit button or else raise the alert to fill
 
Share this answer
 
v2
Comments
SYED SHAHID ALI 18-Apr-14 4:54am    
user can start fill data from any control it may be at last or middle or start
Tom Marvolo Riddle 18-Apr-14 4:59am    
It's not a problem.

for eg. let imagine. you have 10 textbox from textbox1 to textbox10.In the textbox10 check all the fields are filled or not.

It allows the user to fill textbox5 or textbox1 or anything except textbox10.When user fill the Textbox10 ,all the above fields should be filled
SYED SHAHID ALI 18-Apr-14 5:04am    
i can't restrict user to fill textbox10 at last or before submit button
Tom Marvolo Riddle 18-Apr-14 5:15am    
Then use all Textbox textchanged events to check
Create a method for checking and call it in all textchanged events
SYED SHAHID ALI 18-Apr-14 5:33am    
thanx jas for reply i got it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900