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.