How to make a Textbox required IF a Checkbox is checked

前端 未结 6 1131
忘掉有多难
忘掉有多难 2020-12-16 13:33

How can I make a textbox required if a checkbox is checked?

I figure I could write a custom validator, but I was hoping to avoid a full post back to check the valida

6条回答
  •  甜味超标
    2020-12-16 13:47

    There is already a customvalidator validator control, which can fire a client-side javascript method to evaluate the value, or a server-side method to compare the values.

    This has an example: http://msdn.microsoft.com/en-us/library/a0z2h4sw%28VS.80%29.aspx Client property explained here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.clientvalidationfunction.aspx Server event here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.servervalidate.aspx

    You can put code in to cross-reference the checkbox value.

    HTH.

提交回复
热议问题