Hi to all master of asp.net and c#
how to do the client side validation using c# and with out using required field validation control i wrote the code of javascript in head tab and i write in page_load method
protected void Page_Load(object sender, EventArgs e)
{
btnAdd.Attributes.Add("onclick", "return validate()");
}
but its not checking the fields and javascript is
where i am doing mistake i don't know
Loading

Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Aug 11, 2009, 6:06 AM EDT
Master BillaRank #2,229 · 630 reputationPosted Aug 11, 2009, 7:41 AM EDT
When you are write javscript, you keep in mind its JAVA. so you need take all attribute also here.
So here i have corrected your code. try this
protected void Page_Load(object sender, EventArgs e)
{
btnAdd.Attributes.Add("onclick", "return validate();");
}
but its not checking the fields and javascript is
Thank you
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 11, 2009, 9:53 AM EDT
and Even you dont need to use getElementById to Locate Control :)
use it like below code
aspx Code
asp:TextBox ID="txtPrimeNumber" runat="server">asp:TextBox> asp:CustomValidator ID="CustomValidator1" runat="server"ErrorMessage="Invalid Prim Number" ClientValidationFunction="CheckPrime" ControlToValidate="txtPrimeNumber" Display="Dynamic"> asp:CustomValidator>script language="JavaScript"> function CheckPrime(sender, args) { var iPrime = parseInt(args.Value); var iSqrt = parseInt(Math.sqrt(iPrime)); for (var iLoop=2; iLoopif (iPrime % iLoop == 0) { args.IsValid = false; return; } args.IsValid = true; } script> Dont Forget to mark "Do you like answer" it will give some credits to me :)mohdazeemuddin ahmed125 reputationPosted Aug 11, 2009, 9:17 PM EDT
to do validation which is good JavaScript or custom Validation. i don't want do post back if there is any missing field available.
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Aug 11, 2009, 10:29 PM EDT