{"id":2137,"date":"2012-09-17T15:52:08","date_gmt":"2012-09-17T19:52:08","guid":{"rendered":"http:\/\/www.iowawebnet.com\/ein\/?p=2137"},"modified":"2012-09-17T15:59:30","modified_gmt":"2012-09-17T19:59:30","slug":"asp-net-validator-validate-one-of-the-two-values","status":"publish","type":"post","link":"https:\/\/www.iowawebnet.com\/ein\/2012\/09\/asp-net-validator-validate-one-of-the-two-values\/","title":{"rendered":"ASP.NET Validator &#8211; validate one of the two values"},"content":{"rendered":"<p>Validate one of the two textbox values<\/p>\n<pre>\r\nMarkup page\r\n<code>\r\nPlease enter on of at least one contact point:\r\n&lt;asp:CustomValidator ID=\"ContactInfoAlert\" runat=\"server\" \r\nErrorMessage=\"CustomValidator\" OnServerValidate=\"CustomValidator_ServerValidate\">\r\n&lt;\/asp:CustomValidator>\r\n\r\nUser email: \r\n&lt;asp:TextBox ID=\"EmailTbx\" runat=\"server\" ToolTip=\"Enter email.\" >\r\n&lt;\/asp:TextBox>\r\nUser phone: \r\n&lt;asp:TextBox ID=\"PhoneTbx\" runat=\"server\" ToolTip=\"Enter phone number.\" >\r\n&lt;\/asp:TextBox>\r\n&lt;asp:Button ID=\"Btn1\" runat=\"server\" Text=\"Next\" CausesValidation=\"true\"\/>\r\n<\/code>\r\n<\/pre>\n<p><a style=\"display:none;\" id=\"te880456586\" href=\"javascript:expand('#te880456586')\">Click to read more&#8230;<\/a>\n<div class=\"te_div\" id=\"te880456586\"><script language=\"JavaScript\" type=\"text\/javascript\">expander_hide('#te880456586');<\/script><\/p>\n<pre>\r\nCode-behind page\r\n<code>\r\nProtected Sub Btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) \r\n                         Handles Btn1.Click\r\nDim usrEmail As TextBox = Btn1.FindControl(\"EmailTbx\")   'user email\r\nDim usrPhone As TextBox = Btn1.FindControl(\"PhoneTbx\")   'user phone\r\n'validate contact info - at least one required\r\n  If usrEmailTbx.Text = \"\" AndAlso usrPhoneTbx.Text = \"\" Then\r\n     ContactInfoAlert.ErrorMessage = \"Enter email or phone!\"\r\n  Else\r\n    'your code whatever it might be\r\n  End If\r\nEnd Sub\r\nPublic Sub CustomValidator_ServerValidate(ByVal source As Object, \r\n       ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)\r\n        args.IsValid = True\r\n\r\n  If memEmailTbx.Text = \"\" AndAlso memPhoneTbx.Text = \"\" Then\r\n      ContactInfoAlert.ErrorMessage = \"Enter email or phone!\"\r\n\r\n      args.IsValid = False\r\n  End If\r\nEnd Sub\r\n<\/code>\r\n<\/pre>\n<pre>\r\nResult\r\n<code>\r\n<font color=\"red\">Enter email or phone!<\/font><br \/>\r\nUser email: <input id=\"EmailTbx\" name=\"EmailTbx\" type=\"textbox\" style=\"width: 80px;\" disabled\/><br \/>\r\nUser phone: <input id=\"PhoneTbx\" name=\"PhoneTbx\" type=\"textbox\" style=\"width: 80px;\" disabled \/><br \/>\r\n<div style=\"padding-left: 90px;\"><input type=\"button\" id=\"Btn1\" name=\"Btn1\" Text=\"Next\" Value=\"Next\" disabled \/><\/div>\r\n<\/code>\r\n<\/div>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Validate one of the two textbox values Markup page Please enter on of at least one contact point: &lt;asp:CustomValidator ID=&#8221;ContactInfoAlert&#8221; runat=&#8221;server&#8221; ErrorMessage=&#8221;CustomValidator&#8221; OnServerValidate=&#8221;CustomValidator_ServerValidate&#8221;> &lt;\/asp:CustomValidator> User email: &lt;asp:TextBox ID=&#8221;EmailTbx&#8221; runat=&#8221;server&#8221; ToolTip=&#8221;Enter email.&#8221; > &lt;\/asp:TextBox> User phone: &lt;asp:TextBox ID=&#8221;PhoneTbx&#8221; runat=&#8221;server&#8221; ToolTip=&#8221;Enter phone number.&#8221; > &lt;\/asp:TextBox> &lt;asp:Button ID=&#8221;Btn1&#8243; runat=&#8221;server&#8221; Text=&#8221;Next&#8221; CausesValidation=&#8221;true&#8221;\/> Click to read more&#8230; Code-behind page Protected [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,17,16,52,56,84],"tags":[19,27,22],"class_list":["post-2137","post","type-post","status-publish","format-standard","hentry","category-net-4-0","category-applications","category-net","category-controls","category-validation-controls","category-vs2010","tag-asp-net","tag-form-validation","tag-programming"],"_links":{"self":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2137"}],"collection":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/comments?post=2137"}],"version-history":[{"count":26,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2137\/revisions"}],"predecessor-version":[{"id":2161,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2137\/revisions\/2161"}],"wp:attachment":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/media?parent=2137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/categories?post=2137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/tags?post=2137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}