c# - Validation message error not working properly -


i'm having problem validation message errors web forms. need error when both statements true(both fields empty). when change statement && || i'm able error that's not want.thank you. here c# code

protected void customvalidatorform_servervalidate(object source, servervalidateeventargs args)     {         if (string.isnullorempty(drpstate.text) && string.isnullorempty(txtregion.text))             args.isvalid = false;         else         {             args.isvalid = true;         }     } 

i'm trying run code forms:

<asp:dropdownlist id="drpstate"  runat="server" causesvalidation="true"> <asp:listitem></asp:listitem> <asp:listitem value="il">illinois</asp:listitem> <asp:listitem value="in">indiana</asp:listitem> <asp:listitem value="ia">iowa</asp:listitem>  </asp:dropdownlist>     <asp:textbox id="txtregion" runat="server"></asp:textbox>     <asp:button id="btnsubmit" text="submit" runat="server"  />          </div>             <asp:customvalidator id="customvalidatorlist" runat="server"                  controltovalidate ="drpstate" onservervalidate="customvalidatorform_servervalidate"                  errormessage="at least 1 of field need filled out" display="dynamic"                  forecolor="red"                 >              </asp:customvalidator>             <asp:customvalidator id="customvalidatorform" runat="server"                 controltovalidate ="txtregion" onservervalidate="customvalidatorform_servervalidate"                 errormessage="at least 1 of field need filled out" display="dynamic"                 forecolor="red"                  >              </asp:customvalidator> 

try using ,

<asp:textbox id="txtfrom" runat="server"></asp:textbox> <asp:requiredfieldvalidator errormessage="*" controltovalidate="txtfrom" runat="server" display="dynamic" forecolor="red" /> 

easy way this,

after create <asp:textbox id="txtfrom" runat="server"></asp:textbox>

type <asp:requiredfieldvalidator , press tab button twice, can give errormessage define color of errormessage


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -