c# - i have got a validation problem! -


i want validate control myself. put label , condition when press button.

 protected void sendbutton1_click(object sender, eventargs e) {     if (questiondetailstextbox2.text.length > 5000)     {         questiondetailstextbox2.text = "you cant enter more 5000 characters";     }     else if(questiontextbox1.text.length > 100)     {         questiondetailstextbox2.text = "you cant enter more 100 characters";     }     else if (checkvalidation())     {          questiontextbox1.bordercolor = system.drawing.color.red;     }     else     {         response.redirect("answerquestion.aspx");     } } 

i added regular expression validater. did this:

  protected void topicdropdownmenu_selectedindexchanged1(object sender, eventargs e) {     subtopicdropdownlist.items.clear();      string[] chosenitem = topic[topicdropdownmenu.selecteditem.value];      foreach (string item in chosenitem)     {         subtopicdropdownlist.items.add(item);     }  } 

again, need press button twice redirect me :(... ajax still necessary?

if want immediate response have move validation logic client. means write validation logic in javascript , call client side click event of button or change event of textbox before processing postback events.

doing checks in code behind requires round trip server. whether way , postback full page or use ajax , partial postback, there delay while data sent server , client waits response. how big of delay depends on how data needs transferred , network conditions. why ajax faster, gets send smaller batches of data.

however handle client side validation, considered best practice repeat validation logic in code behind. catch instances user has client side scripting disabled.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -