Preventing Double Clicking with Server Side Validation - asp.net

I am trying to prevent users from double clicking on the submit button for a page I'm updating. The problem is that there is server side validation that has to be done to determine if the user has to do any updates before we can move on. I currently have the following code on my submit event for my form.
<asp:Button ID="SubmitPayment" runat="server" OnClientClick="this.disabled='true';" UseSubmitBehavior="false" OnClick="SubmitPayment_Click" Text="Submit" />
Where this becomes an issue is where the page does not pass validation. In this instance everything I have tried to enable the button has failed. It's hard for them to resubmit corrected information with the submit button disabled. I have tried both of the following methods at the end of my validation to re-enable it.
SubmitPayment.Enabled = true;
SubmitPayment.Attributes.Add("disabled", "false);
What must I do to re-enable this control? This is in Visual Studio 2005. Thanks in advance.
-edit-
The approach that I used was as follows. I added an additional decoy button that was disabled and had the display css property set to none. I then used javascript that would hide the submit button and show the decoy button in the OnClientClick event. Finally, the end of the server side method would update the css properties on the buttons to hide and show them afterwards.
Code segments are as follows. Thanks again for the help
function PreventDoubleClick()
{
var sp = document.getElementById("SubmitPayment");
var db = document.getElementById("DecoyButton");
sp.style.display = "none";
db.style.display = "inline";
}
<asp:Button ID="SubmitPayment" runat="server" OnClientClick="javascript:PreventDoubleClick();" UseSubmitBehavior="false" OnClick="SubmitPayment_Click" Text="Submit" />
<asp:Button ID="DecoyButton" Enabled="false" runat="server" style="display:none;" Text="Please Wait..."/>
DecoyButton.Style.Add("display", "none");
SubmitPayment.Style.Add("display", "inline");

I have had a similar problem before and the best solution I came up with was to hide the button and replace it with a please wait (or validating) message. If it fails validation you can then show the button again

Related

LinkButton not firing ASP.NET validators

I have a form that currently uses an control to submit a form. Everything works perfectly. So now the new requirement is for the "submit' button to be a link. Changing it to a LinkButton control, without changing a SINGLE other thing, breaks the validation.
There is a bit too much code to post in a SO question and I know there's a bit of a lack of detail here, but is there any reason why a LinkButton wouldn't fire ASP.NET validation the same way a Button control would? In theory, they should both operate exactly the same, no?
The current submit button:
<asp:Button ID="btnSubmit" TabIndex="9" Text="Send" ValidationGroup="Forward" runat="server" />
The new submit button:
<asp:LinkButton ID="btnSubmit" TabIndex="9" Text="Send" ValidationGroup="Forward" runat="server" />
The Link button should fires the validation the same way a normal button does, my concerns in your case would be the following:
make sure these is nothing in the server side code stopping this.
make sure in the javascript code there is nothing stopping the "
ASP.NET controls that fire validation has a property called CauseValidation
Be sure all controls should fire validation, has this property set to True
Add attribute CauseValidation="True" to your control but if you want to fire this at particular line at code behind you can use validate the form by the following code:
FormID.Validate();
I know this is old but it has never answered. Did your validator have a "controlTovalidate"? Currently it would appear as if the validator was not firing but in reality it is. It just does not have anything that it is 'watching'. Hope if anyone reaches this thread that this helps even if it is just a little bit.
I was unable to determine the cause of this issue but was able to solve it:
I set the CausesValidation="false" and added at the top of the onclick event this.Validate(linkButton.ValidationGroup) this allows the event to get to the code behind and validation to occur.

I want iif conditiomn in my radio button

I want to put if condition in my radio button.
I have wrote this code but it does not give me result as I want. you will get idea from my code what actual I need to do. I have loaded user control two time in a single page so I want to call Java Script in page according to control.
<asp:RadioButton runat="server" GroupName="Pricing" class="2deditable iscreatedbydealer isinprivatelabel" onClick='<%this.ID=="ucPricing_Details_Sale"? "setSalePopupRetailPrice();":"setClearancePopupRetailPrice();"%>'
ID="rbManual" />
I think you can dynamic add the onclick event for the control in page load event of server side.
e.g
if("ucPricing_Details_Sale".Equals(this.ID))
{
this.rbManual.Attributes.Add("onclick", "setSalePopupRetailPrice();");
}
else
{
this.rbManual.Attributes.Add("onclick", "setClearancePopupRetailPrice();");
}
The on OnClick event will run on server side. Try using the OnClientClick event instead.
Edit: Deleted my last statement. Mistook me about the context of the call.
Also added code sample:
<asp:RadioButton runat="server"
OnClientClick='<%this.ID=="ucPricing_Details_Sale"?[...]"%>'
ID="rbManual" />

jquery validation for specific button onclick

i am using jquery client side validation in asp.net.
the problem i am facing now is that whenever i click any button in a page it causes validation rather than for specific button alone.
how to resolve this .?
thank you
Suppose you have two buttons SubmitButton and CancelButton and you do not want to CancelButton to fire validation plugin, just give CssClass="cancel" for CancelButton
<asp:Button ID="CancelButton" runat="server"
Text="Return to List"
CssClass="cancel" />
You want to use event.preventDefault().
http://api.jquery.com/event.preventDefault/
$("button").click(function(event) {
event.preventDefault();
// do stuff here
});

ASP.NET CheckBox disabling postback with javascript

I'm trying to wire up a CheckBox to handle an event when check/unchecked. If the user has JavaScript enabled, use that, otherwise use a postback.
Here is my code:
<asp:CheckBox ID="ApplicationInProcessCheckBox" runat="server"
Text="Application In Process" AutoPostBack="true"
oncheckedchanged="ApplicationInProcessCheckBox_CheckedChanged"
onclick="return false;" />
The return false in the javascript onclick event is disabling the postback. However, it also won't let the box check or uncheck. (I have more code to add to the javascript event... I just want to get the concept working first).
What am I doing wrong?
I think we can't post back on clicking checkbox without Javascript enabled.

How to display a Yes/No style message box in web part, and get client's choice?

I want to show a message box when users trying to do any major operations in my web part. If user choince [Yes], then continue to do sometiing ...[No] for nothing.
How can i implements this function in my web part , Sharepoint 2007 ??
pls help me ~~
thx
If you're using an ASP.Net control like a Button, you can add the following attribute to give the user a JavaScript popup before the postback actually happens:
<asp:Button runat="server" ID="Button1" OnClick="Button1_Click" OnClientClick="return confirm('Are you sure you want to do this?');" />
You can also set this property on the button object in your code:
Button1.OnClientClick = "return confirm('Are you sure you want to do this?');";

Resources