Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the question is releted to javascript.

I have user-control form and aspx form, if there are 4 textbox in user-controland i want to check blank validation of textbox from aspx form where there is an one button in c# asp.net

onclientclick

plz reply as soon as possible
Posted

Suppose we create a user control that has only asp:text box named 'txt', and we have to validate it in our page.

XML
<myText:Textbox ID="txt" runat="server" Visible="true"  />
    <asp:Button ID="btnSumbit" runat="server" Text="Validate user control" OnClientClick="javascritp:return IsFilled()" />



You can use the following JavaScript to get that control.

SQL
var a=document.getElementById('form1').elements("txt$txt");
    if(a.value=='')
    {
        alert("please enter value");
        return false;
    }



Regards
 
Share this answer
 
v2
Hi,

It's a bad idea to validate stuff at client-side. If someone disables JavaScript in his browser, then you don't longer validate the text box. So, ALWAYS validate stuff at server-side!

In this case, use a RequiredFieldValidator, which is server-side:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator%28v=vs.110%29.aspx[^]
http://asp.net-tutorials.com/validation/required-field-validator/[^]
http://www.devmanuals.com/tutorials/ms/aspdotnet/requiredfieldvalidator.html[^]
 
Share this answer
 
v3
 
Share this answer
 
Here are a couple of articles that might help you in achieving what you want:

Understanding ASP.NET Validation Techniques[^]
A Tiny Javascript Framework for Common Validation Scenarios.[^]
 
Share this answer
 
He try this

XML
<script type="text/javascript">


    // Client Side Validation On Save
        $(document).ready(function() {
         //   AddFunctionsOnEvents();

        });
        //------------>
        function AddFunctionsOnEvents() {
            $("#<%=cmdSave.ClientID%>").click(function() {
                return ValidateSaveData();
            });


        }
        //------------>
        //------------>
        function ValidateSaveData(){






        var Email = document.getElementById('<%=txtEmailID.ClientID %>').value;
            if (Email == "") {
                alert("Enter Email ID");
                document.getElementById('<%=txtEmailID.ClientID%>').focus();
                return false;
            }
            //var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/
            var emailPat = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
            var validEmail = emailPat.test(Email);
            //var EmailmatchArray = Email.match(emailPat);
            if (!validEmail) {
                alert("Your email ID seems incorrect. Please try again.");
                document.getElementById('<%=txtEmailID.ClientID%>').focus();
                return false;}

               if (document.getElementById("<%=txtPassword.ClientID %>").value == "") {
                alert("Enter Password");
                document.getElementById('<%=txtPassword.ClientID%>').focus();
                return false;
            }


                if (document.getElementById("<%=txtPassword.ClientID %>").value != document.getElementById("<%=txtConfrmPwd.ClientID %>").value ) {
                alert("Password and Confirm Password Should be Same");
                document.getElementById('<%=txtConfrmPwd.ClientID%>').focus();
                return false;
            }
}
</script>
 
Share this answer
 

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