我有这个标记代码:
<div id="rowIndirizzo" class="form">
<label>
Indirizzo:</label>
<asp:DropDownList ID="ddlToponimo" CssClass="indirizzo" runat="server" DataTextField="Toponimo"
DataValueField="Toponimo">
</asp:DropDownList>
<asp:TextBox ID="txtStrada" CssClass="textinputStrada" runat="server"></asp:TextBox>
<asp:TextBox ID="txtNumCivico" CssClass="textinputCivico" runat="server"></asp:TextBox>
</div>
<div id="divCap" class="form">
<label>
CAP:</label>
<asp:TextBox ID="txtCAP" CssClass="textinputCAP" runat="server"></asp:TextBox>
</div>
<asp:RequiredFieldValidator ID="rfvToponimo" CssClass="errore2" runat="server" ControlToValidate="ddlToponimo"
ErrorMessage="Il campo toponimo dell'indirizzo è obbligatorio." Display="Dynamic"
ValidationGroup="Step4_StruttPrivata1Step" Style="color: Red; display: block !important;"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="rfvStrada" CssClass="errore2" runat="server" ControlToValidate="txtStrada"
ErrorMessage="Il campo strada dell'indirizzo è obbligatorio." Display="Dynamic"
ValidationGroup="Step4_StruttPrivata1Step" Style="color: Red; display: block !important;"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="rfvNumCivico" CssClass="errore2" runat="server" ControlToValidate="txtNumCivico"
ErrorMessage="Il campo numero civico dell'indirizzo è obbligatorio." Display="Dynamic"
ValidationGroup="Step4_StruttPrivata1Step" Style="color: Red; display: block !important;"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="rfvCAP" CssClass="errore2" runat="server" ControlToValidate="txtCAP"
ErrorMessage="Il campo CAP è obbligatorio." Display="Dynamic"
ValidationGroup="Step4_StruttPrivata1Step" Style="color: Red;
display: block !important;"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revCAP" runat="server" ControlToValidate="txtCAP"
ValidationExpression="^([0-9]{5})$" ErrorMessage="Il formato del CAP è errato (Es. 01234)"
Display="Dynamic" ValidationGroup="Step4_StruttPrivata1Step" Style="color: Red;
display: block !important;" />
<asp:Button ID="btnSearchIndirizzo" OnClientClick="return false;" class="buttonnext" runat="server" Text="Inserisci"
ValidationGroup="Step4_StruttPrivata1Step"></asp:Button>
我有一些控制来验证按钮点击,但我不想要回发(我不能使用输入按钮,因为不要激活rfv)。我试过onclientclick事件......但没有。
答案 0 :(得分:5)
更新:我修改了dummyFunction代码以显式触发客户端验证,并在页面无效时停止回发。
在按钮标记上尝试以下属性
UseSubmitBehavior = false
您可能还想尝试
OnClientClick = "return dummyFunction();"
然后有一个JS函数dummyFunction,如
function dummyFunction(){
//this command will explicitly fire the validation
Page_ClientValidate();
return Page_IsValid; //Page_IsValid is set to true or false depending on whether a page is valid or not after client validation
}
答案 1 :(得分:0)
你可以在进入onClientClick之前让页面进行验证我的意思是你可以从OnClientClick触发它来执行必需的字段验证器。
只需在客户端点击功能中添加:
function myOnClientClick()
{
if(Page_ClientValidate())//这将触发验证器
{
//然后做客户端的东西
}
}