vb.net - Show Error using Tag Property C# -
i want know on how error using tag property? have code in vb.net not know convert c#.
scenario: textbox_qty accepts integers. if user types non-numeric character, shows tag property saying invalid characters.
this code used in vb.net. use if has null fields.
private function validfield(byval paramarray ctl() object) boolean integer = 0 ubound(ctl) if ctl(i).text = "" error_reg.seterror(ctl(i), ctl(i).tag) return false exit function end if next return true end function if validfield(textbox_username, textbox_password, textbox_retypepassword, textbox_lastname, textbox_firstname, comboxbox_group, combobox_question, textbox_answer) = false exit sub if code not work? there code can show error in tag property without converting vb.net code c#?
thank helping me!
it may worthwhile check information class, has methods validating objects. while visualbasic class, can still used in c# 1 of main benefits of .net framework.
in visual basic not need add references project.
if want use information class in c# make sure add reference microsoft.visualbasic in project, add using microsoft.visualbasic; class or module adding following code to.
you can use information.isnumeric method validate numeric entry.
example vb.net code...
private function validfield(byval paramarray ctl() object) boolean integer = 0 ubound(ctl) dim tb textbox = directcast(ctl(i),textbox) if not isnumeric(tb.text) error_reg.seterror(tb, tb.tag) return false end if next return true end function example c# code...
private bool validfield(params object[] ctl) { (int = 0; <= information.ubound(ctl); i++) { textbox tb = (textbox)ctl[i]; if (!information.isnumeric(tb.text)) { error_reg.seterror(tb, tb.tag); return false; } } return true; } also exit function after return statement not needed, return automatically exits function result.
Comments
Post a Comment