我要验证文本框字段。当我在javascript末尾删除return false时,验证控件运行良好。但是删除return false不会提交数据。我还观察到,当我使用return false时,数据已成功提交,但在提交数据后检查了验证。
function ConvertToImage(btnExport) {
html2canvas($("#myDIV")[0]).then(function(canvas) {
var base64 = canvas.toDataURL();
$("[id*=hfImageData]").val(base64);
__doPostBack(btnExport.name, "");
});
return false;
}
<asp:TextBox runat="server" ID="custom_Name" Height="50px" ValidationGroup="vg" Width="250px"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Font-Size="X-Large" ControlToValidate="custom_Name" ErrorMessage="Please Enter Product Name" ValidationGroup="vg"></asp:RequiredFieldValidator>
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Only Alphabets are Allowed" Font-Size="X-Large" ControlToValidate="custom_Name" ValidationExpression="[a-zA-Z ]*$" ValidationGroup="vg"></asp:RegularExpressionValidator>
<!--Button for save image start-->
<asp:HiddenField ID="hfImageData" runat="server" />
<asp:Button ID="btnExport" Text="Export to Image" runat="server" CausesValidation="true" OnClick="ExportToImage_Click" OnClientClick="return ConvertToImage(this)" CssClass="btnstyle" ValidationGroup="vg" Height="50px" Width="200px" />
<!--Button for save image ends-->
答案 0 :(得分:0)
您需要在javascript:
中添加OnClientClick
。
OnClientClick="return ConvertToImage(this)"
将
OnClientClick="javascript:return ConvertToImage(this)"