Design Q - Avoiding two clicks

R

Ramsi

My development environment is ASP.Net 1.1. Clicked event of a button has
lengthy procedure it will take 2 to 4 seconds to process the data.

My question is,

1.. If the user clicks the button again, will the clicked event called
again?
2.. If yes to the above question how to avoid these kinds of scenarios?
Thanks for your suggestions.
Ramsi
 
L

Lucas Tam

My development environment is ASP.Net 1.1. Clicked event of a button has
lengthy procedure it will take 2 to 4 seconds to process the data.

My question is,

1.. If the user clicks the button again, will the clicked event called
again?
Yes.

2.. If yes to the above question how to avoid these kinds of scenarios?
Thanks for your suggestions.

-Use javascript to disable the button
-Check if the current function is in progress? Maybe put a flag in the
database?
 
R

Ramsi

Is it possible to disable a image button through the java script?
Thanks for your reply.
Ramsi
 
J

John Hann

Ramsi said:
Is it possible to disable a image button through the java script?
Thanks for your reply.
Ramsi

Yes and no. I do the following to build this sort of functionalty...
Instead of using an ImageButton for your button, use a LinkButton
instead. Be sure not to specify its text so it is not visible to the
user, and remap your ImageClick event handler to the new LinkButton.
Don't specify its Visible property, the default value of true is
required for this to work. Now, in place of your ImageButton, insert an
IMG tag for your button image. In your page, you will need to define a
javascript function that handles the clientside onClick event for this
IMG tag, and a global variable that tracks the "enabled" state of your
button. The client code should look something like this:

<script lang=javascript>
var GameEnabled = true;

function imgCommencePimpin_Click()
{
if (GameEnabled)
{
GameEnabled = false;
__doPostBack( 'lnkCommencePimpin', '');
}
}
</script>

<ASP:LinkButton ID="lnkCommencePimpin" OnClick="lnkCommencePimpin_Click"
runat=server />
<IMG src="..\Images\CommencePimpin.gif"
onclick="imgCommencePimpin_Click();">

This is definitely a hack, but it works unless your button is in a user
control. I'll assume its not, but I can show you how to do that too if
you need to know. BTW, if anyone reading this knows a more convenient
way to insert custom client-side script logic into stock ASP.NET
controls, I'm all ears.

- John
 
R

Ramsi

Thank you very much.

John Hann said:
Yes and no. I do the following to build this sort of functionalty...
Instead of using an ImageButton for your button, use a LinkButton
instead. Be sure not to specify its text so it is not visible to the
user, and remap your ImageClick event handler to the new LinkButton.
Don't specify its Visible property, the default value of true is
required for this to work. Now, in place of your ImageButton, insert an
IMG tag for your button image. In your page, you will need to define a
javascript function that handles the clientside onClick event for this
IMG tag, and a global variable that tracks the "enabled" state of your
button. The client code should look something like this:

<script lang=javascript>
var GameEnabled = true;

function imgCommencePimpin_Click()
{
if (GameEnabled)
{
GameEnabled = false;
__doPostBack( 'lnkCommencePimpin', '');
}
}
</script>

<ASP:LinkButton ID="lnkCommencePimpin" OnClick="lnkCommencePimpin_Click"
runat=server />
<IMG src="..\Images\CommencePimpin.gif"
onclick="imgCommencePimpin_Click();">

This is definitely a hack, but it works unless your button is in a user
control. I'll assume its not, but I can show you how to do that too if
you need to know. BTW, if anyone reading this knows a more convenient
way to insert custom client-side script logic into stock ASP.NET
controls, I'm all ears.

- John
 
C

Craig Deelsnyder

Is it possible to disable a image button through the java script?
Thanks for your reply.
Ramsi


Lucas Tam said:
-Use javascript to disable the button
-Check if the current function is in progress? Maybe put a flag in the
database?
Yes, you can but would not be my preferred way of doing it....check the
HTML you have right now, it's pry an a href="" wrapped around an img. Add
an onclick attribute to the hyperlink (I think you can do this by setting
it on the ImageButton) and it should run before posting back. So you
could put in that event some javascript that checks a local var that
indicates whether this function ran once before.

The only tricky thing is if you have validators...you may want to then
actually override __doPostBack in Javascript and insert the flipping of
the flag there (actually pry the best design regardless)...

http://groups.google.com/groups?hl=...stback&sourceid=opera&num=0&ie=utf-8&oe=utf-8

I like this approach better, as it catches double posting by any control
on a page...
 
J

John Hann

Ramsi said:
John,
I am finding difficulty to display an image for a Link button.
Thanks,
Ramsi

I think you missed the key point of my post, which was that you need to
put the button's image in a standard html IMG tag, not an ImageButton or
Link Button. Then, you need to add a javascript onclick event handler to
that IMG tag that calls a javascript function that will trick ASP.Net
into thinking that the user clicked on a LinkButton, even though the
user cannot actually see that LinkButton. I'll resubmit my code with
some additional changes for clarity. Hope this helps.
- John

<script lang=javascript>
// if this variable is true, imgYourButtonImage_Click() will simulate
// the user clicking on lnkYourLinkButton, even though it is not
displayed to the user
var ButtonEnabled = true;

// this is called whenever the IMG tag that contains your button
image is clicked
function imgYourButtonImage_Click()
{
if (ButtonEnabled == true)
{
// this ensures that if the user clicks your button IMG
again, a postback will not occur
ButtonEnabled = false;

// this tells ASP.Net that the user clicked on
lnkYourLinkButton
__doPostBack( 'lnkYourLinkButton', '');
}
}
</script>

<%-- This is the link button that you need to implement a server-side
event handler for.
It is hidden from the user and only "clicked" indirectly from
imgYourButtonImage_Click().
Do not set the Visible property to false or this won't work. --%>
<ASP:LinkButton ID="lnkYourLinkButton" OnClick="lnkYourLinkButton_Click"
runat=server />

<%-- This is the place where your button image is displayed to the user.
Whenever it is clicked,
imgYourButtonImage_Click() is called. The style attribute makes
cursor behave as it does
with any other button. --%>
<IMG src="BUTTON_IMAGE_PATH_HERE" onclick="imgYourButtonImage_Click();"
style="cursor:hand">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top