Prevent ModalPopupExtender from displaying using JavaScript actions

In my ASP.net project, I am using Ajax with .Net 2.0. One of the challenges I am facing is related to a ModalPopupExtender that is linked to an image button:

<asp:ImageButton ID="ibStartNow" runat="server" ImageUrl="images/StartNow.gif" 
    ToolTip="Save expense report header and start now!" CausesValidation="False" 
    OnClientClick="CheckReason(); NoPrompt();" />

The issue arises with the OnClientClick event where a JavaScript function named CheckReason is called. This function checks if a textbox named "reason" has any input. If it doesn't, then I do not want the ModalPopupExtender to open.

Below is the JavaScript function in question:

function CheckReason()
{
    var txtReason = document.getElementById('txtReason');
    var txtReasonVal = txtReason.value;
    if (txtReasonVal.length > 0 && txtReasonVal != 'Enter the reason for creating this expense report...')
    { 
        return true;
    }
    else
    {
        txtReason.style.borderStyle='solid';
        txtReason.style.borderColor='red';
        return false;
    }
}

Even when the function returns false, the modal popup extender opens anyway. I need a solution for preventing the popup from opening in this scenario.

Answer №1

Check to see if this solution works for you

When the button is clicked, run the functions CheckReason() and NoPrompt() in JavaScript and return the result.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to add filtering to my MongoDB when using the find() method in express routing? If so, how can

Hey there! I have this GET function that uses async to find a specific "Category" mongoose Schema that the user just clicked on, along with another "Tool" mongoose Schema which fetches all tools from my database and sends them both to a rendered page. I&a ...

Calculating Future Dates in JavaScript by Adding Days

I am looking to add 20 days to the current date and present the output in the mm/dd/yyyy format. Presently, with today being 05/15/2014, the result produced is 05/35/2014, which is clearly an invalid date. var currentYear = new Date(); alert((currentYea ...

What is the best way to have my transparent navigation bar float on top of my background in a parallax-scrolling website?

Currently, I am working on creating a website with a navigation bar that has no background and floats on top of a background image. However, I am facing an issue with my parallax-scrolling website. Whenever the page is scrolled to the second section, the n ...

Having trouble populating Extjs Grid with JSON data

In this simple grid, I am attempting to display three columns - Subject ID, Subject Name, and Subject Short Name by obtaining JSON data. The data is stored in a variable called myData in JSON format, which has been received from the server. Despite pasting ...

The connection between the layout of dropdown menus and the way data is handled in forms

I have discovered three different methods for creating dropdowns that can be used in forms: 1) Utilizing HTML with "form-dedicated" attributes such as select and option value="" 2) Implementing the Bootstrap framework with div classes like "dropdown", Butt ...

Creating a JQuery Dialog Box Integrated with DataTable()

I need some assistance with a problem I'm encountering while using Asp.net and JQuery UI 1.9.2. On my form, I have a textbox and a search button. Upon clicking the button, I query the database on the server side and store all the results in a Gridview ...

Leveraging jQuery within a method defined in an object using MyObject.prototype.method and the 'this' keyword

Recently, I've started exploring Object-oriented programming in JavaScript and have encountered a challenge. I'm trying to define an object like the example below, where I am using jQuery inside one of the methods. I'm curious about the best ...

Craft fresh items within HTTP request mapping

I am currently working on a function that subscribes to a search api. Within the map function, my goal is to transform items into objects. I haven't encountered any errors in my code, but the response always turns out empty. Here's the snippet o ...

When utilizing the POST method, the information is submitted to the server without being displayed

Why is my POST method not displaying on the webpage when the GET method does, even though I have not created a method for it in my global.js file? Does the GET method automatically come with POST? I specifically want my POST method to be displayed and not ...

Show a single jQuery Validation error

I am struggling with displaying an error message at the top if validation fails, without using the errorPlacement option. Instead, I want to showcase the message in a Bootstrap alert box. Below is the HTML code snippet: <form method="POST" action="/ro ...

Using JQuery Masked Input to Prevent Illegal Characters in Filenames

I am currently attempting to implement the masked input JQuery plugin into my code in order to restrict special characters that are not allowed in a Windows Filename system from being entered into a textbox. Specifically, I am looking for the correct .ma ...

What could be causing the invisibility of my drop down list items?

I am having trouble creating two cascading drop-down lists. The first one is functioning correctly; however, when I move to the second drop-down list, I can see that the correct number of options are being generated based on the items in the database, but ...

Add C# iteration with JavaScript on ASP.NET directories

I need help extracting all filenames from a specific folder on the server, and then adding them to a JavaScript array. The functionality should mimic ASP.NET C#'s Directory.GetFiles method. I have already initialized an array and now just require as ...

Toggle button visibility in AngularJS based on checkbox selection

I'm currently utilizing ng-table to construct my table. I have a button positioned at the top of the table that is initially disabled. My goal is to enable this button only when any of the checkboxes are selected. The button should automatically disab ...

Display information using HTML elements within a loop in JavaScript

I am facing an issue with iterating over an array of objects in JavaScript. Each object contains multiple parameters, and my goal is to extract the data from each object and display it in a table or a grid format. Here is an example of my code: function ...

Mastering smooth zoom and scroll effects in JavaScript without any flickering

My web application has a zoom feature that scales some absolutely positioned DIVs while keeping the scroll position intact. However, during the animated zooming, there is a noticeable flickering effect where the boxes seem to jump up and down slightly. I a ...

Navigating to a new address using ajax and express routing

I am facing an issue with a button having an ID of 'tune-in' on a page named auth.ejs. The button is supposed to navigate to a new page called index.ejs when clicked. However, instead of rendering the index page, clicking the button keeps me on ...

Issue with the scope of Bootstrap Accordion

Observing that the event triggers on a single Bootstrap accordion can affect all other accordions on the same page, I am wondering if there is a way to isolate this behavior without altering the markup or using $(this). Any suggestions? Check out this exam ...

Shadows with pixel art style in Threejs

I developed an application where I dynamically created shelves. Everything is working fine except for the shadows. I'm not sure if the issue lies with the lighting or the objects themselves. Can anyone provide some assistance? Here is a snapshot showc ...

Alert event in JavaScript navigating between different pages

My website features two dynamic php pages: customer invoices and customer management. One common request from my users is the ability to swiftly add a new customer directly from the customer invoices page. Instead of cluttering the customer invoices page ...