Reputation: 106
I have a text box with a text change event attached with it;
<asp:TextBox ID="txtLoadPortCode" MaxLength="8" runat="server" ToolTip="Load Port Code" CssClass="form-control form-control-Mandatory" OnTextChanged="txtLoadPortCode_TextChanged" AutoPostBack="true"></asp:TextBox>
On text change it fires a server side event to fetch the Name from Database, if Name is missing it shows a Javascript alert triggered from server side.
ScriptManager.RegisterStartupScript(this, GetType(), "OriginPortMissing", "$(function(){alert(\"This combination '" + this.txtLoadPortCode.Text + "' of Country, City & Site is not available in Master table. Please provide a valid Code.\");});", true);
I also have a submit button which has a Javascript field validation attached with it;
<asp:LinkButton ID="btnSubmitCreateRequest" runat="server" CssClass="btn btn-primary btn-custom btn-Custom-Link" OnClick="btnSubmitCreateRequest_Click" OnClientClick="return ValidateFields();">
<i class="fa fa-paper-plane" aria-hidden="true"></i>
<span>Submit Booking</span>
</asp:LinkButton>
On ValidateFields() function I have written field validation for multiple controls and If any validation fails it shows error message in 'alert' window.
So the scenario is, if User gives some value in text-box and directly clicks on the Submit button then both text change event and Submit button javascript validation gets fired, resulting double alert message at the same time (IE 11 browser).
Is there any way I can restrict Submit button validation event?
Upvotes: 3
Views: 177
Reputation: 8271
Initally Don't Show the LinkButton
, set it to visible="false"
, after the Text Change (I mean in the Textchanged
event) try to set LinkButton
the visible="true"
Upvotes: 3
Reputation: 723
For this just time limit or just delay the validation by using setTimeOut
setTimeOut(function(){ put your validation code },10000)
Upvotes: 1
Reputation: 1368
There is provision in Jquery. by using event.stopImmediatePropagation()
. https://api.jquery.com/event.stopimmediatepropagation/][1]
Please check this once. This might help you.
Upvotes: 0