asp.net - Show red border on textbox on error -


i trying show error changing color of border of text box. have found lot of posts on how it, have never done 'validators' confused start, or put code.

similar posts:

post one

post two

my main question(s) are, put js code? , secondly, how call code?

current code

 if ticketnumber.text = string.empty = true         notificationlabel.text = "ticket number must filled out"         exit sub     end if 

a requiredfieldvalidator tricks explained here, , here. way use customvalidator following.

aspx mark-up

<asp:textbox runat="server" id="tbtext" /> <asp:customvalidator id="cvcustom" errormessage="ticket number must filled out"      controltovalidate="tbtext" runat="server" onservervalidate="validateinput"      clientvalidationfunction="validateinput" validateemptytext="true" /> <asp:button text="my button" runat="server" /> 

javascript

 <script type="text/javascript">     function validateinput(sender, args) {         if (args.value == '') {             args.isvalid = false;             document.getelementbyid('<%= tbtext.clientid %>').style.bordercolor = "red";             return false;         }         return true;     } </script> 

code behind (c#)

protected void validateinput(object source, servervalidateeventargs args) {     if(string.isnullorwhitespace(args.value))     {         args.isvalid = false;         tbtext.style["border-color"] = "red";     }     else     {         args.isvalid = true;     }    } 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -