Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sir,

I have 5 text boxes, txt1, txt2, txt3, txt4 and txt5.

I use 2 buttons, one for insert and one for submit in different table.


My question is how to use all textbox validation on insert button and how to use two texbox validation on submit button?



thanks in advance,
Posted
Updated 22-Dec-11 20:19pm
v3
Comments
Dalek Dave 21-Dec-11 6:48am    
Edited for Readability.

Javascript will work for you. here is hint for you

JavaScript
function ValidateTextboxes(objID)
{
   if(document.getElementById(objID).value == "Insert") //check if insert button press
   {
     //validate all textboxes
   }
   elseif(document.getElementById(objID).value=="Submit") //check if submit button pressed
   {
      //validate only 2 textboxes
   }
}


call above function on onclient click of button with id as parameters
C#
<asp:button id="btnSubmit" runat="server" value="click me" onclientclick="ValidateTextboxes(this.id)" />
 
Share this answer
 
make it false for Causesvalidation property of the button
 
Share this answer
 
this link very useful for that problem

fist check iis version if your iis version is lower than the the server iis version then follow this link

http://blog.nkadesign.com/2008/windows-2008-the-microsoftjetoledb40-provider-is-not-registered-on-the-local-machine/[^]
 
Share this answer
 
You need to make like this

ASP.NET
  <div>
    <asp:textbox id="txt1" text="sheraj" style=" text-decoration:blur" runat="server" ></asp:textbox>
    
<asp:requiredfieldvalidator id="r1" controltovalidate="txt1" errormessage="error1" validationgroup="btng" runat="server" ></asp:requiredfieldvalidator>
      
    <asp:textbox id="txt2" runat="server" ></asp:textbox>

--here u need to use two RequiredFieldValidatorfro 2nd text box 
    
     <asp:requiredfieldvalidator id="RequiredFieldValidator1" controltovalidate="txt2" errormessage="error1" validationgroup="bt1" runat="server" ></asp:requiredfieldvalidator>
 
     <asp:requiredfieldvalidator id="RequiredFieldValidator2" controltovalidate="txt2" errormessage="error2" validationgroup="bt2" runat="server" ></asp:requiredfieldvalidator>
 
     <asp:button id="btn1" runat="server" validationgroup="bt1" text="insert " >
    </asp:button>
      
     <asp:button id="btn2" runat="server" validationgroup="bt2" text="update">
      </asp:button>
  
   <asp:button id="btn3" runat="server" causesvalidation="false" text="some opretion">
      </asp:button>

</div>


hope it will help you.
 
Share this answer
 
v2
You can use javascript for that.

Java
  <script type="text/javascript" language="javascript">
function validate
{

 if (document.getElementById("<%=txtName.ClientID%>").value=="")
      {
                 alert("Name Feild can not be blank");
                 document.getElementById("<%=txtName.ClientID%>").focus();
                 return false;
      }
      if(document.getElementById("<%=txtEmail.ClientID %>").value=="")
      {
                 alert("Email id can not be blank");
                document.getElementById("<%=txtEmail.ClientID %>").focus();
                return false;
      }

} 

</script>



and use this function on your cs page like

C#
btnSubmit.Attributes.Add("onclick", "return validate()")
 
Share this answer
 
v2
Comments
Dalek Dave 21-Dec-11 6:51am    
Edited for code block and I deleted the duplicated 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