ajax - asp.net checkbox custom validation -


i trying make website using asp.net dynamic data entities , need checkbox in website must checked in order insert new record. having trouble validating checkbox. have tried server side custom validators people have postes on website aome reason aren't working..any clue on if implementation different if dynamic data entity application?

these different things have tried far:

attempt 1:

made new class:

[attributeusage(attributetargets.property, allowmultiple = false, inherited = false)] public class mustbetrueattribute : validationattribute {     public override bool isvalid(object value)     {         return value != null && value bool && (bool)value;     } } 

and called metadata file in following way:

[mustbetrue(errormessage="error")]

public bool checkbox12 { get; set; }

that doesn't work.

then tried else:

attempt 2:

on aspx page:

<asp:dynamiccontrol id="mycheckbox" runat="server" datafield="checkbox12" mode="insert" /> <asp:customvalidator runat="server" id="cvisactive"   onservervalidate="cvisactive_servervalidate">you must select checkbox</asp:customvalidator>  

and on aspx.cs page:

 protected void cvisactive_servervalidate(object source,servervalidateeventargs args)     {                   if(args.value.length==1)             args.isvalid = true;         else             args.isvalid = false;         }     

the 2nd attempt gives me error message whether clicked or not. tried replacing the args.value.length :

args.isvalid = mycheckbox.checked

however gives error name mycheckbox not exist in current context

thanks lot!

   if (checkbox1.checked == true)     {//do code here..     } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -