Solved

how can I disable the form button after it has been clicked? - Novice Question

Posted on 2004-08-19
12
1,326 Views
Last Modified: 2007-11-27
Hi There,

I am wondering how I can disable the form button after it has been clicked, currently I am using the "onclick" event for the actual function I need to insert records. Has anyone got any good ideas about where I can place the function call?

Sean

onClick="Insertlisting_Click"

onclick="disableform()"

function disableform()
{

document.forms[0].SubmitButtton.disabled = true;
document.forms[0].SubmitButtton.value = 'Please wait...';
document.forms[0].submit();
}
0
Comment
Question by:bullrout
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 11838870
Hi,

you have to do it by javascript, not in the code behind
to that you have to use

SubmitButton.Attributes.Add("onclick", "disableform()")

Regards,
B..M
0
 
LVL 5

Author Comment

by:bullrout
ID: 11839046
Hi There,

I'm not too sure where I have to place the code, do I just add it into the button control itself like below?

Sean

<asp:button id="btnSubmit" text="place listing"  onClick="Insertlisting_Click"  SubmitButton.Attributes.Add "onclick", "disableform()") runat="server" EnableViewState="False" />
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11839209
nope, sorry that i've not been so clear
you have to place this code in the Page_load event

Regards,
B..M
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:bullrout
ID: 11839249
ok so if I have a code behind with a page_load event, how can I call this ?

sean
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11839308
using the
SubmitButton.Attributes.Add("onclick", "disableform()")
the .net framework will assing the client event for this button and when you press the button it will try to call disableform function on the client

you have to assign the page_load event to the page ( this is done autmatically except if you write the definition by hand

Regards,
B..M
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 11839321
Hi,
try this
in the .cs file(the code behind file)
private void Page_Load(object sender, System.EventArgs e)
{

      btnSubmit.Attributes.Add("OnClick","javascript:disableform();");
}

in the aspx file write this
<HTML>
<HEAD>
<title>MyTitle</title>
<script language="javascript">
function disableform()
{

document.forms[0].SubmitButtton.disabled = true;
document.forms[0].SubmitButtton.value = 'Please wait...';
document.forms[0].submit();
}                  
</script>
</HEAD>

if you still have problem with this technique then have a look at this article
http://www.codeproject.com/aspnet/ClickOnce_Button_Control.asp

Regards,
venki
0
 
LVL 5

Author Comment

by:bullrout
ID: 11839386
Hi Venki,

The function seems to overide the validation I have on the page, do I need to call the required field validator that I have on the page inside this javascript fucntion?

Sean
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 11839552
Hi,
I don't thinkk it will override the validation, I think the validation fires first, then the onClick I am not sure in this I need to check that.

Regards,
venki
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11840254
Put this in the page load and you can re-enable whenever you need.

If page.ispostback Then
Mybutton.visibile = false
End If

Regards,

Aeros
0
 
LVL 5

Author Comment

by:bullrout
ID: 11841169
I will try this and let you guys know the outcome.
0
 
LVL 20

Accepted Solution

by:
ihenry earned 500 total points
ID: 11841716
With this you shouldn't have problem with your validation control

How to prevent multiple clicks of a submit button in ASP.NET
http://aspzone.com/articles/207.aspx
0
 
LVL 20

Expert Comment

by:ihenry
ID: 11841757
And don't forget to check this link to try the demo and download the code.
http://aspzone.com/archive/2004/01/06/292.aspx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question