I have a webform application
In Master Page I have the form
<body class="tile-1-bg">
<form id="form1" runat="server">
and in my page.aspx
<div class="control-group" runat="server" id="divNome">
<label for="txtNome" class="control-label">Nome o Ragione Sociale*</label>
<div class="controls">
<asp:TextBox runat="server" ID="txtNome" class="form-control input-sm" required></asp:TextBox>
</div>
</div>
<asp:Linkbutton runat="server" ID="lnkBtnRegistrati" class="btn btn-default btn-lg btn-block" Text="REGISTRATI" OnClientClick="if(checkForm())return true; else return false;" OnClick="lnkBtnRegistrati_Click"></asp:Linkbutton>
I would like to call a Javascript function that simulate Button submit and return false if some validation goes wrong and shows the errors on form fields.
function checkForm()
{
?
}
How can I do?
What you want is to return the result of the checkform
, you can handle it's state in checkform
method it self:
Aspx code
change from
<asp:Linkbutton runat="server" ID="lnkBtnRegistrati" class="btn btn-default btn-lg btn-block" Text="REGISTRATI" OnClientClick="if(checkForm())return true; else return false;" OnClick="lnkBtnRegistrati_Click"></asp:Linkbutton>
to
<asp:Linkbutton runat="server" ID="lnkBtnRegistrati" class="btn btn-default
btn-lg btn-block" Text="REGISTRATION" OnClientClick="return checkform();"
OnClick="lnkBtnRegistrati_Click"></asp:Linkbutton>
In your javascript method:
function checkForm()
{
if(true) // your condition to check
{
return true;
}
else{
return false;
}
}
Explanation :
In the Markup Onclientclick
will return whether your condition met or not , if your conditions are satisfied , then you would be returning as return true
vice versa . so in this way you can achieve what you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With