473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Disable submit button after user click

GS
Hi,

This is probably known solution but I have not found it in minimum amount of code.
I'd like to disable button on client-side after clicking on it.
Just disabling it in javascript do not produce postback event.
Any examples in ASP.NET 2.0?

Thanks,

Jan 19 '06 #1
8 9955
> This is probably known solution but I have not found it in minimum amount
of code.
I'd like to disable button on client-side after clicking on it.


Don't know about 2.0, but this works in 1.1, give it a try:

1. in the PageLoad event

if (!IsPostBack)
{
ibSomeButton.Attributes.Add("onclick",
"this.style.display='none';");
// other stuff
}

The "ibSomeButton" is an ImageButton. However, this will not prevent the
user from hitting refresh which can generate a postback.
Jan 19 '06 #2

Peter Zolja wrote:
This is probably known solution but I have not found it in minimum amount
of code.
I'd like to disable button on client-side after clicking on it.


Don't know about 2.0, but this works in 1.1, give it a try:

1. in the PageLoad event

if (!IsPostBack)
{
ibSomeButton.Attributes.Add("onclick",
"this.style.display='none';");
// other stuff
}

The "ibSomeButton" is an ImageButton. However, this will not prevent the
user from hitting refresh which can generate a postback.


This will hide the button and not disable it. But the goad is still
acheived. May this will work:

idSomeButton.Attributes.Add("onclick", "this.disabled= 'disabled' ");

Jan 19 '06 #3
> This will hide the button and not disable it. But the goad is still
acheived. May this will work:

idSomeButton.Attributes.Add("onclick", "this.disabled= 'disabled' ");


That's correct, but form my experience users don't notice the disabled
state... and still try to click it... so what I do is hide the button and
unhide some text that tells them to wait...
Jan 19 '06 #4
GS
Thanks,

But I wanted to use Button not ImageButton.
I actuallty found the piece of code to do it, the only problem is that
Page.GetPostBackEventReference is obsolete and I'm supposed to use some new
ASP.NET 2.0 method which I have not figured out how.

btnGetImportInfo.Attributes["onclick"] =
"this.disabled=true;this.value='Please wait...';" +
Page.GetPostBackEventReference(btnGetImportInfo ).ToString();

"Peter Zolja" <csu10711atmail.claytonstate.net> wrote in message
news:ei*************@TK2MSFTNGP09.phx.gbl...
This is probably known solution but I have not found it in minimum amount
of code.
I'd like to disable button on client-side after clicking on it.


Don't know about 2.0, but this works in 1.1, give it a try:

1. in the PageLoad event

if (!IsPostBack)
{
ibSomeButton.Attributes.Add("onclick",
"this.style.display='none';");
// other stuff
}

The "ibSomeButton" is an ImageButton. However, this will not prevent the
user from hitting refresh which can generate a postback.

Jan 19 '06 #5
> This will hide the button and not disable it. But the goad is still
acheived. May this will work:

idSomeButton.Attributes.Add("onclick", "this.disabled= 'disabled' ");


I have wanted to do this for a long time, however using a method such
as this one does not work (or at least, did not work for me in v1.1)
because if the page was invalid, the onclick would disable the button,
but the form would not be submitted due to the invalid data.

For example, imagine there is a required field called name, which the
user leaves blank and presses submit. The submit button gets disabled,
and then the user is asked to enter their name. Problem.

Or am I missing something?

Daniel.

Jan 19 '06 #6
> Or am I missing something?

If you do the field checking on the client side then yes, you have a
problem -- which can be solved by checking first and only if successful
disable/hide the button. If, however, you allow a postback and do the
checking on the server side everything should be fine since after a postback
the page comes back with the button enabled/visible -- the default value...
Jan 19 '06 #7
> But I wanted to use Button not ImageButton.

I image it's the same... haven't tried though... (my code was using an
ImageButton and I just took it from there)
I actuallty found the piece of code to do it, the only problem is that
Page.GetPostBackEventReference is obsolete and I'm supposed to use some
new ASP.NET 2.0 method which I have not figured out how.

btnGetImportInfo.Attributes["onclick"] =
"this.disabled=true;this.value='Please wait...';" +
Page.GetPostBackEventReference(btnGetImportInfo ).ToString();


Sorry, I'm still in the 1.1 land. Untested code, try this:

btnGetImportInfo.Attributes.Add("onclick",
"this.disabled=true;this.value='Please wait...';");
Jan 19 '06 #8
GS
Code below will not work since disabling button happens before postback and
hence no postback happens when you disable button.

"Peter Zolja" <csu10711atmail.claytonstate.net> wrote in message
news:ev**************@TK2MSFTNGP14.phx.gbl...
But I wanted to use Button not ImageButton.


I image it's the same... haven't tried though... (my code was using an
ImageButton and I just took it from there)
I actuallty found the piece of code to do it, the only problem is that
Page.GetPostBackEventReference is obsolete and I'm supposed to use some
new ASP.NET 2.0 method which I have not figured out how.

btnGetImportInfo.Attributes["onclick"] =
"this.disabled=true;this.value='Please wait...';" +
Page.GetPostBackEventReference(btnGetImportInfo ).ToString();


Sorry, I'm still in the 1.1 land. Untested code, try this:

btnGetImportInfo.Attributes.Add("onclick",
"this.disabled=true;this.value='Please wait...';");

Jan 19 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bruno Alexandre | last post by:
Hi guys, If I want to block a user to change a form after submiting, I add a function that will disable the submit button, but when I'm getting the form collection (using post or get...
4
by: KS | last post by:
Im trying to prevent the user from clicking any other links on my page when the user have selected/clicked a href once. Sometimes it takes a while before the next page loads so some user will try...
5
by: http://links.i6networks.com | last post by:
I want to force the users to click submit to submit the forms. How do I disable "Enter Key" which will submit the form automatically when they entered the data in text field then pressed "enter key"
14
by: Sinity | last post by:
Anyone knows the method/codes to disable the clicked button after first click by using .aspx-- to prevent people to click many time when waiting for the server response. I tried to do this by...
6
by: GD | last post by:
Hi, I wonder how to disable the "submit" behavior of a button. What I want is to assign values to dynamically added user controls without page postback. Problem: dynamically created control can...
2
by: Ghafran Abbas | last post by:
Call this function from the Page_OnLoad event of your asp.net page. This will prevent the user from doing multiple post backs or button clicks. This was designed to not disable the button, because...
3
by: Jeff | last post by:
I have a payment form with a submit button. A large percentage of users double-click the submit button thus submitting their payment information twice. I would like to use javascript to disable...
16
by: Barry Gilmore | last post by:
Is there a way to disable a button after it is clicked? I am trying to avoid having someone click on it twice while they wait for it to process. Thank you!
5
by: zlf | last post by:
How to disable button once it is clicked on the page? The codes in click event of submit button is time-costing(about 4-5 secs), in this period, user maybe do a re-submit, that is not expected. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.