473,796 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9970
> 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.At tributes.Add("o nclick",
"this.style.dis play='none';");
// other stuff
}

The "ibSomeButt on" 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.At tributes.Add("o nclick",
"this.style.dis play='none';");
// other stuff
}

The "ibSomeButt on" 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.At tributes.Add("o nclick", "this.disab led= '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.At tributes.Add("o nclick", "this.disab led= '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.GetPostBac kEventReference is obsolete and I'm supposed to use some new
ASP.NET 2.0 method which I have not figured out how.

btnGetImportInf o.Attributes["onclick"] =
"this.disabled= true;this.value ='Please wait...';" +
Page.GetPostBac kEventReference (btnGetImportIn fo ).ToString();

"Peter Zolja" <csu10711atmail .claytonstate.n et> wrote in message
news:ei******** *****@TK2MSFTNG P09.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.At tributes.Add("o nclick",
"this.style.dis play='none';");
// other stuff
}

The "ibSomeButt on" 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.At tributes.Add("o nclick", "this.disab led= '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.GetPostBac kEventReference is obsolete and I'm supposed to use some
new ASP.NET 2.0 method which I have not figured out how.

btnGetImportInf o.Attributes["onclick"] =
"this.disabled= true;this.value ='Please wait...';" +
Page.GetPostBac kEventReference (btnGetImportIn fo ).ToString();


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

btnGetImportInf o.Attributes.Ad d("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.n et> wrote in message
news:ev******** ******@TK2MSFTN GP14.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.GetPostBac kEventReference is obsolete and I'm supposed to use some
new ASP.NET 2.0 method which I have not figured out how.

btnGetImportInf o.Attributes["onclick"] =
"this.disabled= true;this.value ='Please wait...';" +
Page.GetPostBac kEventReference (btnGetImportIn fo ).ToString();


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

btnGetImportInf o.Attributes.Ad d("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
1529
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 (form/querystring) I can't retrieve that button value... Is there any trick to do this? Like https://www.cuworld.com/ webpage... Try to register as a free user membership and after click the submit button check what hapend... They
4
56677
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 clicking other links or the same link. I can prevent this when i use buttons by calling onclick and in a javascript getElementsByTagName("input") and then check the type to be type of "button" or "submit" which i then disable. It works. This also...
5
33307
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
7196
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 adding a java script for the button. But, useless.. Please help! Thank you
6
4052
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 not be accessed because the button click trigers page postback(see sample code). When the button is clicked, an error occurs: "System.NullReferenceException: Object reference not set to an instance of an object." Please help. Thanks.
2
8925
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 asp.net 1.x will not pick up the button click event. Instead, it monitors the on submit event of the form and the _doPostBack event of the asp.net page. It overrides the _doPostBack and onsubmit events and checks whether the page has already...
3
3171
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 the submit button once it's been clicked, yet still have the form submit. I can do this in ASP 2.0, however, ASP.Net seems to be adversely affected if you disable the submit button. Here's how I have it set up... The submit button is a...
16
3461
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
2326
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. Thanks zlf
0
9680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.