Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
hi to all,
Here i need how to avoid multiple click, here i done that process.now need is if i click save validation message show two time.how to avoid that.

coding is:-

script:

C#
function ClientSideClick(myButton) {

            if (typeof (Page_ClientValidate) == 'function')
               {
                if (Page_ClientValidate() == false)
                { return false; }
            }


            if (myButton.getAttribute('type') == 'button') {

                myButton.disabled = true;

            }


button is:-

SQL
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                                                                  CssClass="savebutton1231" EnableTheming="false" SkinID="skinBtnSave" onclientclick="ClientSideClick(this)" UseSubmitBehavior="false" OnClick="InsertButton_Click"></asp:Button>




i need how to avoid same validation message twice.
Posted
Comments
Sergey Alexandrovich Kryukov 21-Jul-15 9:21am    
Not clear. You cannot avoid any clicks, because clicks are performed not by your code, but by the users. If you need to disable some button of first click, just do it.
—SA
JOTHI KUMAR Member 10918227 21-Jul-15 9:42am    
hmm k but i done that but before button click i write some validation for textbox that is called twice.

if using an updatepanel you can grey out the screen once the client clicks the button using css. this will prevent a secondary click.

XML
<ProgressTemplate>
<div class="divWaiting">


XML
.divWaiting{
position: absolute;
background-color: black;
z-index: 2147483647 !important;
opacity: 0.6;
overflow: hidden;
text-align: center; top: 0; left: 0;
height: 100%;
width: 100%;
padding-top:20%;
}
 
Share this answer
 
I have used the solution below with success. I had gotten this script from a co-worker of mine. It uses JavaScript functions to disable and enable the button. While disable it also sets the button image to a .gif to indicate processing.

Forgive me if this was already posted as a solution on another thread.

JavaScript
function disableBtn(btnID, newText) {
    //initialize to avoid 'Page_IsValid is undefined' JavaScript error
    Page_IsValid = null;
    //check if the page request any validation   
    // if yes, check if the page was valid
    if (typeof (Page_ClientValidate) == 'function') {
        Page_ClientValidate();
        //you can pass in the validation group name also
    }
    //variables
    var btn = document.getElementById(btnID);
    var isValidationOk = Page_IsValid;
    /********NEW UPDATE************************************/   
    //if not IE then enable the button on unload before redirecting/ rendering   
    if (navigator.appName !== 'Microsoft Internet Explorer')
    {
           EnableOnUnload(btnID, btn.value);   
    }   
    /***********END UPDATE ****************************/   
    // isValidationOk is not null
    if (isValidationOk !== null) {
        //page was valid
        if (isValidationOk) {
            btn.disabled = true;
            btn.value = newText;
            btn.style.background = 'url(~/images/ajax-loader.gif)';
        }
        else {//page was not valid
            btn.disabled = false;
        }
    }
    else {//the page don't have any validation request
        setTimeout("setImage('"+btnID+"')", 10);
        btn.disabled = true;
        btn.value = newText;
    }
}

//set the background image of the button
function setImage(btnID) 
{
    var btn = document.getElementById(btnID);
    btn.style.background = 'url(images/loading.gif)';
}

//enable the button and restore the original text value
function EnableOnUnload(btnID, btnText)
{
    window.onunload = function()
    {
            var btn = document.getElementById(btnID);
            btn.disabled = false;
            btn.value = btnText;
    }
}


Include a call to disableBtn OnClientClick with UseSubmitBehaviour set to false.

ASP.NET
<asp:button id="btnSubmit" runat="server" onclientclick="disableBtn(this.id, 'Submitting...')" text="Submit" usesubmitbehavior="False" xmlns:asp="#unknown" />
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 22-Jul-15 2:54am    
hi i used above script but validation show twice how to resolve that. i prevent double click but validation message show twice.how to avoid. below i give my design for my text-box and this is formview


<td class="ControlLabelproject" style="width: 24%">Ref. No. *
<asp:RequiredFieldValidator ID="rvRefNo" runat="server" ControlToValidate="txtRefNo"
Text="*" ErrorMessage="Please enter Ref. No. It cannot be left blank." CssClass="rfv" Display="Dynamic"
EnableClientScript="True">
</td>
<td class="ControlTextBox3" style="width: 25%">
<asp:TextBox ID="txtRefNo" runat="server" Text='<%# Bind("RefNo") %>' SkinID="skinTxtBoxGrid">

</td>
[no name] 22-Jul-15 10:00am    
I'm not sure I understand. What validation shows twice? Can you include the markup for the button also please?
JOTHI KUMAR Member 10918227 23-Jul-15 9:05am    
please see my above question from starting.if i use that script validation message show twice in single click.how to prevent this.can any one help me for this .
[no name] 23-Jul-15 15:43pm    
Is it the validation control message that is showing? Is it a JavaScript popup message? I have no idea what validation message you are referring to, from the code above I cannot determine what you are referring to.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900