Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
4.80/5 (5 votes)
See more:
Hi Everyone,

I am preparing a message sending feature. There after writing the message if I click on the submit button for 3 to 4 times, it is posting for 3 to 4 times. To control this I used the following code:

C#
protected void imgbtnSend_Click(object sender, ImageClickEventArgs e)
{
    imgbtnSend.OnClientClick = "this.disabled = true; " + ClientScript.GetPostBackEventReference(new PostBackOptions(imgbtnSend));
    //code for messaging
}


Now it is working fine in my local system. But it is not working after deploying in server.

I want to make it a single post at a time.

Any suggestion please.
Posted
Updated 22-Oct-10 1:38am
v3
Comments
PSK_ 22-Oct-10 6:47am    
After deploying are you getting any error and what is the behavior of button after click?
arindamrudra 22-Oct-10 7:04am    
No, I have not get any error.

Try Following Code............

C#
protected void Page_Load(object sender, EventArgs e)
    {
        btnsave.Attributes.Add("onclick",      "this.disabled=true;this.value='Processing....';" + ClientScript.GetPostBackEventReference(btnsave, "").ToString());      

}

 protected void btnsave_Click(object sender, EventArgs e)
     {
     }
 
Share this answer
 
Comments
arindamrudra 12-Oct-11 10:33am    
Thanks Tushar.
you can fixed it aspx page.

MSIL
function ConfirmBooking(imgLoad)
    {
    document.getElementById('imgbtnsubmit').style.display = none;
    document.getElementById(imgLoad).style.display = block;
    return true;
    }

<img id="imgLoad" src="images/Progress.gif" alt="" style="display: none;" runat="server" />
<asp:ImageButton ID="imgbtnsubmit" runat="server" OnClientClick="javascript:return ConfirmBooking('imgLoad');"
    ImageUrl="images/submit.gif" OnClick="imgbtnSend"/>

    protected void imgbtnSend_Click(object sender, ImageClickEventArgs e)
    {
    }
 
Share this answer
 
Comments
arindamrudra 25-Oct-10 8:30am    
Thank you for your help.
C#
protected void imgbtnSend_Click(object sender, ImageClickEventArgs e)
{

// you better write code to validate whether the message is empty before sending //message and also write code to  clear the message after sending the message.

}
 
Share this answer
 
Comments
arindamrudra 22-Oct-10 8:03am    
protected void imgbtnSend_Click(object sender, ImageClickEventArgs e)
{
//if (Page.IsValid == true)
{
if (txtMessageContent.Value != "")
{
imgbtnSend.OnClientClick = "this.disabled = true; " + ClientScript.GetPostBackEventReference(new PostBackOptions(imgbtnSend));
//Codes
}
}
}

here the txtMessageContent is the tinyMCE
arindamrudra 22-Oct-10 8:09am    
So I am not going in that way. I want a way so that if the validation message comes then the button will be enabled and also in case of tinyMCE, so I used ClientScript.GetPostBackEventReference(new PostBackOptions(imgbtnSend)).

and at the time if it passes the "if" condition then the button will be disabled.

It is working fine in local system.
But not in Server
Example:

function DisableButton() {
var flag = true;

    for (var i = 0; i < Page_Validators.length; i++) {
        ValidatorValidate(Page_Validators[i]);

        if (!Page_Validators[i].isvalid)
            flag = false;
    }

if(flag == true)
    document.getElementById("<%= btnSubmit.ClientID %>").visibility="hidden";
    return true;
    }


add OnClientClick="return DisableButton()==true?true:false;" to the button property.
 
Share this answer
 
v4
Comments
arindamrudra 22-Oct-10 6:52am    
Hi Shakil, thanks for your help.
But there is Server side Validation (ASP Validation) also. So if I use

OnClientClick="return DisableButton()==true?true:false;"

Then if I Get the validation error for the first time, then will it work?
shakil0304003 24-Oct-10 10:40am    
If you have validators then you have to write a javascript function, which fire validators & check each validators are validate, if all are fine then it will visibility hidden to the button.
shakil0304003 24-Oct-10 10:59am    
I have improved my answer, i think it will fill your requirement. If it is not full your requirement, you can mail me, some days ago, i have solved this problem. :)
arindamrudra 25-Oct-10 0:37am    
Please check your yahoo email id.
shakil0304003 25-Oct-10 1:03am    
I have improved my answer again :)

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