ASP.net project using ajax (.net 2.0).
I've got 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();" />
Notice the OnClientClick event there is a js function called CheckReason, this function simply checks a textbox called reason to see if anyone has entered anything. If they haven't I do NOT want the ModalPopupExtender to actually open.
Here is that JavaScript function although ugly :)
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;
}
}
The issue is even if I hit the else and return false, the modal popup extender still opens the modal popup. I need it so that it does not open up the pop up.
See if this helps
OnClientClick="javascript:var ret = CheckReason(); NoPrompt(); return ret;"
Related
I want to prevent the double/triple clicking issue for my "Done" button in my application.
I have my "Done" button as below in my .jsp file:
<ip:button name="Done"
text="Done"
jsEvent="onclick=\"if(submitPage() && doneSubmit())
{ request.value = 'DONE_REQUEST'; submit(); }\"" />
And the submitPage() is the JavaScript method as below:
function submitPage(){
if (pageLoaded && !hasSubmitted ){
hasSubmitted = true;
return true;
}
else{
return ! showWaitMsg();
}
}
submitPage() method is used by other buttons as well.
So I was thinking to using the submitPage() method to disable "Done" button (only the "Done" button) once the button is clicked and enable it once "hasSubmitted = true;".
Can anyone please advise how could I do it?
Error is coming when ever I click on the button
Microsoft JScript runtime error: Sys.ParameterCountException: Parameter count mismatch.
Function.emptyFunction = Function.emptyMethod = function Function$emptyMethod() {
/// <summary locid="M:J#Function.emptyMethod" />
if (arguments.length !== 0) throw Error.parameterCount();
}//Error is occuring here.
Yes, I am using JavaScript confirm message in this page which is included in a master page, update panel and ScriptManager as well on the client click of the button, and after clicking this button error is coming below is my code
function Confirm() {
if(document.getElementById('<%= btnSave.ClientID %>').value=="UPDATE")
{
if(document.getElementById('<%= userStatus.ClientID %>').value=="INACTIVE")
{
if (confirm("do you want to make the user INACTIVE? \n By making the user INACTIVE means its all assigned role will be revoked"))
{
document.getElementById("confirm_value").value = "Yes";
}
else
{
document.getElementById("confirm_value").value = "No";
}
}
else
{
document.getElementById("confirm_value").value = "active";
}
}
}//endFun
Actually I am using ScriptManager in the master page and Update Panel so to get rid of this error I set “ScriptMode="Release" “ of ScriptManeger and it works now no that error is not coming any more.This is the link which helped me out
http://msdn.microsoft.com/en-us/library/bb344940%28v=vs.110%29.aspx
I'm having some weird issues with the disabled attribute of an asp button and JavaScript, probably due to my lack of experience, but anyway...
As I understand from this question/answer, setting the disabled attribute makes the element disabled. Unless you set it like so; element.disabled = false;
So, that's what I do in my code;
<script type="text/javascript">
function CheckOne(inChkBox) {
... irrelevant code goes here ...
var rejectButton = document.getElementById('btnReject');
if (inChkBox.checked) {
rejectButton.disabled = false;
rejectButton.className = 'Enabled';
} else {
rejectButton.disabled = true;
rejectButton.className = 'Disabled';
}
}
</script>
<input type='checkbox' name='chkRejectLineItem' onchange='CheckOne(this);' runat="server"/>
This seems to trigger and work fine (the cssclass changes at the very least...) apart from the fact that my button is still disabled;
<asp:Button ID="btnProjectTimeReject" runat="server" Text="Reject Selected" OnClientClick="LineItemRejectReason();" OnClick="btnProjectTimeReject_Click" Enabled="False" CssClass="Disabled"/>
I know this, because the OnClientClick never gets called (for some reason, the server side code still gets called??). If I set the button to Enabled="True" then everything works as expected.
Is it because I'm using Enabled="True" initially and I should instead use rejectButton.removeAttribute('disabled') in the enable/disable JavaScript?
After a lot of console debugging and googling the same thing different ways, I found the following solution/answer.
var rejectButton = document.getElementById('btnPLReject');
if (inChkBox.checked) {
rejectButton.disabled = false;
rejectButton.className = 'Enabled';
$('#btnPLReject').bind("click", function() { LeaveRejectReason(); });
} else {
rejectButton.disabled = true;
rejectButton.className = 'Disabled';
}
This causes the button to trigger the JavaScript/Client side code AND then the Server side code...where as it was only doing the Server side code before...
I need some panadol now.
I have an ASPxButton (DevExpress). On its ClientSideEvents, I need a simple check. If it passes it, it can postback, but if not, it shouldn't postback. My button is;
<dx:ASPxButton ID="MKREkle" runat="server" AutoPostBack="false" OnClick="Show_MKRPopup" Text="MKR Ekle">
<ClientSideEvents Click="OpenMKRPopUp"/>
</dx:ASPxButton>
The Javascript function is;
function OpenMKRPopUp(s, e) {
if (IsBitirmeGrid.GetFocusedRowIndex() != -1) {
MKRPopup.Show();
} else {
alert('.....!');
return false;
}
}
As I checked the answers, everyone said that return false should work but it doesn't. Can you tell me a way?
It looks like there is another event listener attached to this button. return or preventDefault() should prevent for submitting any form.
Disable a post back from asp.net i.e. buttons, links, gridview page index changing and sorting etc when a post back is already in progress. Target browser is IE 6+. I've written these 2 javascript I am not sure how to apply it on GridView Page Index changing.
<script type="text/javascript">
//isFormSubmitted variable is used to prevent the form submission while the server execution is in progress
var isFormSubmitted = false;
//If the form is already submitted, this function will return false preventing the form submission again.
function SubmitForm(msg)
{
try {
if(isFormSubmitted == true)
{
alert('A post back is already in progress. Please wait');
return false;
}
else
{
var res = false;
if (msg)
{
res = confirm(msg);
}
if (res == true)
{
isFormSubmitted = true;
}
return res;
}
} catch(ex) {}
}
function VerifySubmit()
{
if(isFormSubmitted == true)
{
alert('A post back is already in progress. Please wait');
return false;
}
else
{
isFormSubmitted = true;
return true;
}
}
</script>
For buttons I can attach the SubmitForm to OnClientClick like this.
<asp:Button ID="btnCancel" runat="server" CssClass="button" Text="Cancel" OnClick="btnCancel_Click" OnClientClick="return SubmitForm('Do you want to continue with cancelling recent action?');" />
But I am not sure how to attach the VerifySubmit to non prompting controls like gridview pager.
onclick="this.disabled=true;"
on your submit-button(s) is all the javascript "magic" you need
When jQuery is an option you can use this small script to disable all submit-buttons:
// Find ALL <form> tags on your page
$('form').submit(function(){
// On submit disable its submit button
$('input[type=submit]', this).attr('disabled', 'disabled');
});
Found here: http://jquery-howto.blogspot.com/2009/05/disable-submit-button-on-form-submit.html
Or you can block the whole page: http://jquery.malsup.com/block/#page
If you want to disable post back set autopastback=false for buttons links.
Otherwise you need to give us more information and better instructions / details to help you out.
I'm going to guess that you're doing ajaxy type stuff here and you have an async-postback going and you don't want the user to click a button at that time.
If that is the case then try the following code:
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(startRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
function startRequest(sender, e) {
//disable search button during the AJAX call
document.getElementById('<%=btnSearch.ClientID%>').disabled = true;
}
function endRequest(sender, e) {
//re-enable the search button once the AJAX call has completed
document.getElementById('<%=btnSearch.ClientID%>').disabled = false;
}
The easiest solution I found is that..
//In the head section define this script...
<script type="text/javascript">
function ShowProcessingMsg(confirmMsg) {
var resp = confrim(confirmMsg);
try {
if (resp == true) {
var divC = document.getElementById('<%= divControls.ClientID %>');
var divM = document.getElementById('<%= divProcessingMsg.ClientID %>');
if (divC && divM) {
divC.display = "none";
divM.display = "block";
}
else {
return false;
}
}
} catch (exp) { alert(exp); return false; }
return resp;
}
</script>
//This div will show during processing since by default it's display is none when after
//Post back your page loaded again this will not be diplayed. We are going to set it's
//diplay attribute to block from javascript.
<div id="divProcessingMsg" runat="server" display="none" z-index="1000" />
<b>Processing.... Please wait.</b>
</div>
//We will hide this div from script by setting its display attribute to none. Since
//by default this attribute is block when the page loaded again it'll be displayed by
//default. So no special handling for setting display again to block is required.
<div id="divControls" runat="server" display="block" z-index="1" />
<asp:GridView ............ >
.....
.....
.....
<asp:Button runat="server" id="btnProcess" Text="Process" OnClientClick="return ShowProcessingMsg('Do you want to continue with processing'); OnClick="btnProcess_ServerClick" />
</div>