Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict multiple events in ASP .net & Javascript

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?

like image 231
Abhijit_Srikumar Avatar asked Aug 11 '26 16:08

Abhijit_Srikumar


2 Answers

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"

like image 191
Tummala Krishna Kishore Avatar answered Aug 14 '26 08:08

Tummala Krishna Kishore


For this just time limit or just delay the validation by using setTimeOut

setTimeOut(function(){ put your validation code },10000)
like image 34
aditya shrivastava Avatar answered Aug 14 '26 08:08

aditya shrivastava