473,387 Members | 1,517 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,387 software developers and data experts.

Adding onClick to submit button

When we use

btnSubmit.Attributes["onClick"] = "javascript: this.disabled=true;"

to make the button disabled and prevent users from clicking it again while
form data still posting, there is no longer postback. I.e. the button does
go disabled, but the form does not invoke submit() method. Of course, it
does work fine without this property.

Clues?

--
Dmitry Korolyov [d_**@removethispart.mail.ru]
MVP: Windows Server - Active Directory
Nov 18 '05 #1
4 5559
Dmitry,

The explanation for this is a tough one. Instead of explaining why (I don't
have enough room here.) let me point you to some working code:

I have a javascript object on my website that I created so I could easily
attach commonly used javascripts to .Net objects. One javascript included in
the component is a disable submit script. The object is available for free,
including the entire .Net v.1.1 project, on my web site:
www.aboutfortunate.com. Just click the code library link on the top right of
the page and then click the "Javascript" button in the menu on the left.

At the very least you will be able to see the source code for how I solved
this.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Dmitry Korolyov [MVP]" <d_**@removethispart.mail.ru> wrote in message
news:uu**************@TK2MSFTNGP11.phx.gbl...
When we use

btnSubmit.Attributes["onClick"] = "javascript: this.disabled=true;"

to make the button disabled and prevent users from clicking it again while
form data still posting, there is no longer postback. I.e. the button does
go disabled, but the form does not invoke submit() method. Of course, it
does work fine without this property.

Clues?

--
Dmitry Korolyov [d_**@removethispart.mail.ru]
MVP: Windows Server - Active Directory

Nov 18 '05 #2
Thanks for the tip. I've looked through your code and have a question now:
does Page_ClientValidate invoke a form.submit() ? If no (I guess no), then I
don't see how it helps - it looks like adding *any* onClick event to form
submit button cancels form submission at all, and you have to invoke it
manually. I've used the following temporarily solution for my case:

btnSubmit.Attributes["onClick"] = "javascript:
this.disabled=true;document.forms[0].submit();"

I understand it is quite ugly and might break things out if we have more
than one form. However, I don't see any other solution in this situation
where adding anything to onClick cancels form submission. Maybe I'm setting
this attribute in a wrong place (Page_Load)? Something else probably?

--
Dmitry Korolyov [d_**@removethispart.mail.ru]
MVP: Windows Server - Active Directory
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
Dmitry,

The explanation for this is a tough one. Instead of explaining why (I
don't
have enough room here.) let me point you to some working code:

I have a javascript object on my website that I created so I could easily
attach commonly used javascripts to .Net objects. One javascript included
in
the component is a disable submit script. The object is available for
free,
including the entire .Net v.1.1 project, on my web site:
www.aboutfortunate.com. Just click the code library link on the top right
of
the page and then click the "Javascript" button in the menu on the left.

At the very least you will be able to see the source code for how I solved
this.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Dmitry Korolyov [MVP]" <d_**@removethispart.mail.ru> wrote in message
news:uu**************@TK2MSFTNGP11.phx.gbl...
When we use

btnSubmit.Attributes["onClick"] = "javascript: this.disabled=true;"

to make the button disabled and prevent users from clicking it again while form data still posting, there is no longer postback. I.e. the button does go disabled, but the form does not invoke submit() method. Of course, it
does work fine without this property.

Clues?

--
Dmitry Korolyov [d_**@removethispart.mail.ru]
MVP: Windows Server - Active Directory

Nov 18 '05 #3
Dmitry,

..Net places a folder containing javascripts it uses on the web server.
Page_ClientValidate does indeed submit the form if the page is found to be
valid.

The beauty of using the script I've provided is that it uses the built in
..Net functionality to disable the submit button and submit the form only if
the page is found to be valid client side. If you disable the submit button
without doing it this way and then someone tries to submit a non-valid form
the form won't submit because the validation will stop it but then the
submit button will be disabled. Or you'll have disabled the ability to
validate client side.

Go ahead and try out the script you'll be pleasantly surprised. It works
perfectly.
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Dmitry Korolyov [MVP]" <d_**@removethispart.mail.ru> wrote in message
news:eM**************@TK2MSFTNGP11.phx.gbl...
Thanks for the tip. I've looked through your code and have a question now:
does Page_ClientValidate invoke a form.submit() ? If no (I guess no), then I don't see how it helps - it looks like adding *any* onClick event to form
submit button cancels form submission at all, and you have to invoke it
manually. I've used the following temporarily solution for my case:

btnSubmit.Attributes["onClick"] = "javascript:
this.disabled=true;document.forms[0].submit();"

I understand it is quite ugly and might break things out if we have more
than one form. However, I don't see any other solution in this situation
where adding anything to onClick cancels form submission. Maybe I'm setting this attribute in a wrong place (Page_Load)? Something else probably?

--
Dmitry Korolyov [d_**@removethispart.mail.ru]
MVP: Windows Server - Active Directory
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
Dmitry,

The explanation for this is a tough one. Instead of explaining why (I
don't
have enough room here.) let me point you to some working code:

I have a javascript object on my website that I created so I could easily attach commonly used javascripts to .Net objects. One javascript included in
the component is a disable submit script. The object is available for
free,
including the entire .Net v.1.1 project, on my web site:
www.aboutfortunate.com. Just click the code library link on the top right of
the page and then click the "Javascript" button in the menu on the left.

At the very least you will be able to see the source code for how I solved this.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Dmitry Korolyov [MVP]" <d_**@removethispart.mail.ru> wrote in message
news:uu**************@TK2MSFTNGP11.phx.gbl...
> When we use
>
> btnSubmit.Attributes["onClick"] = "javascript: this.disabled=true;"
>
> to make the button disabled and prevent users from clicking it again

while
> form data still posting, there is no longer postback. I.e. the button

does
> go disabled, but the form does not invoke submit() method. Of course, it > does work fine without this property.
>
> Clues?
>
> --
> Dmitry Korolyov [d_**@removethispart.mail.ru]
> MVP: Windows Server - Active Directory
>
>


Nov 18 '05 #4
OK, thanks for the clarification, Justin. The script definitely works, its
just me curious about details.

--
Dmitry Korolyov [d_**@removethispart.mail.ru]
MVP: Windows Server - Active Directory
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
Dmitry,

.Net places a folder containing javascripts it uses on the web server.
Page_ClientValidate does indeed submit the form if the page is found to be
valid.

The beauty of using the script I've provided is that it uses the built in
.Net functionality to disable the submit button and submit the form only
if
the page is found to be valid client side. If you disable the submit
button
without doing it this way and then someone tries to submit a non-valid
form
the form won't submit because the validation will stop it but then the
submit button will be disabled. Or you'll have disabled the ability to
validate client side.

Go ahead and try out the script you'll be pleasantly surprised. It works
perfectly.
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Dmitry Korolyov [MVP]" <d_**@removethispart.mail.ru> wrote in message
news:eM**************@TK2MSFTNGP11.phx.gbl...
Thanks for the tip. I've looked through your code and have a question now: does Page_ClientValidate invoke a form.submit() ? If no (I guess no), then
I don't see how it helps - it looks like adding *any* onClick event to form submit button cancels form submission at all, and you have to invoke it
manually. I've used the following temporarily solution for my case:

btnSubmit.Attributes["onClick"] = "javascript:
this.disabled=true;document.forms[0].submit();"

I understand it is quite ugly and might break things out if we have more
than one form. However, I don't see any other solution in this situation
where adding anything to onClick cancels form submission. Maybe I'm setting this attribute in a wrong place (Page_Load)? Something else probably?

--
Dmitry Korolyov [d_**@removethispart.mail.ru]
MVP: Windows Server - Active Directory
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:ec**************@TK2MSFTNGP11.phx.gbl...
Dmitry,

The explanation for this is a tough one. Instead of explaining why (I
don't
have enough room here.) let me point you to some working code:

I have a javascript object on my website that I created so I could easily attach commonly used javascripts to .Net objects. One javascript included in
the component is a disable submit script. The object is available for
free,
including the entire .Net v.1.1 project, on my web site:
www.aboutfortunate.com. Just click the code library link on the top right of
the page and then click the "Javascript" button in the menu on the left.
At the very least you will be able to see the source code for how I solved this.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Dmitry Korolyov [MVP]" <d_**@removethispart.mail.ru> wrote in message
news:uu**************@TK2MSFTNGP11.phx.gbl...
> When we use
>
> btnSubmit.Attributes["onClick"] = "javascript: this.disabled=true;"
>
> to make the button disabled and prevent users from clicking it again while
> form data still posting, there is no longer postback. I.e. the button does
> go disabled, but the form does not invoke submit() method. Of

course,
it > does work fine without this property.
>
> Clues?
>
> --
> Dmitry Korolyov [d_**@removethispart.mail.ru]
> MVP: Windows Server - Active Directory
>
>


Nov 18 '05 #5

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

Similar topics

3
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a...
2
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick...
0
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta...
11
by: Neo Geshel | last post by:
Greetings. Hopefully someone will be able to untie this Gordian Knot I have found myself bound up in. I am trying to add a submit button dynamically to a PlaceHolder. This button will help...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
2
by: darrel | last post by:
I am using a javascript WYSIWYG text editor for our CMS. To grab the proper content we need to add a javacsript call to the form: Form1.Attributes.Add("onSubmit", "myOnSubmitEventHandler();") ...
0
by: none | last post by:
Hi, I’ve got a problem with my onclick handlers for command buttons being dropped on page render for a popup window. On the opening window, I have several command buttons, and they all have...
2
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so...
3
by: didi86 | last post by:
Please help me to adding multiple row at a time... // Last updated 2006-02-21 <script language="javascript"> function addRowToTable() { var tbl = document.getElementById('tblSample'); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.