gicio Posted October 23, 2003 Posted October 23, 2003 Hi! I have a litte problem with my CustomValidator. What my CustomValidator should do: The CustomValidator should check if 2 textboxes are empty.. if yes he should diplay a message. This is my code: <asp:customvalidator id="CustomValidator1" runat="server" ErrorMessage="Sie müssen min. 1 Telefonnummer angeben" Display="Static" OnServerValidate="ValidateExistanceOfPhones"></asp:customvalidator></P> <script runat="server"> void ValidateExistanceOfPhones(object source, ServerValidateEventArgs args) { args.IsValid = !((m_txtTelephoneNumber.Text.Length == 0) && (m_txtMobileNumber.Text.Length == 0)); } </script> the calidator check ValidateExistanceOfPhones. but when args.IsValid = false the message isn't shown. What is the problem??! Make I something wrong? 2. quastion: is it possible to check the state of the 2 textboxes on the client side? when YES how? best regards, gicio Quote
WebJumper Posted October 23, 2003 Posted October 23, 2003 to check on the clientside you have to use javascript. add this block before the </head> tag <script language="javascript"> function jsCheckTextBoxes() { if (document.forms[0].TextBox1.value == "" || document.forms[0].TextBox2.value == "") { alert("Bitte beide TextBoxen ausfüllen"); return false; } else { return true; } } </script> now you have to code when this function should be fired. for any <asp:button> write in your code-behind file following (i do it in pageload of server-code) Button1.Attributes.Add("onclick", "return jsCheckTextBoxes();"); if the function return true, your asp-button submits the page. if it return false, no submit will be done! regards! Quote
gicio Posted October 23, 2003 Author Posted October 23, 2003 Thx WebJumper !!!! but what is the better solution? check this on the server or client site ??? regards, gicio Quote
Moderators Robby Posted October 23, 2003 Moderators Posted October 23, 2003 Wether you do it on the client is up to you, but either way you should do it on the server Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.