468,249 Members | 1,491 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

Design Q - Avoiding two clicks

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
Nov 18 '05 #1
7 1648
"Ramsi" <Ra********@hotmail.com> wrote in news:egDY$YxhEHA.1344
@TK2MSFTNGP11.phx.gbl:
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?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #2
Is it possible to disable a image button through the java script?
Thanks for your reply.
Ramsi
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"Ramsi" <Ra********@hotmail.com> wrote in news:egDY$YxhEHA.1344
@TK2MSFTNGP11.phx.gbl:
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?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 18 '05 #3
Ramsi wrote:
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
Nov 18 '05 #4
Thank you very much.

"John Hann" <jovinhan@SPAM_FREEyahoo.com> wrote in message
news:JZ********************@comcast.com...
Ramsi wrote:
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

Nov 18 '05 #5
John,
I am finding difficulty to display an image for a Link button.
Thanks,
Ramsi

"John Hann" <jovinhan@SPAM_FREEyahoo.com> wrote in message
news:JZ********************@comcast.com...
Ramsi wrote:
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

Nov 18 '05 #6
On Fri, 20 Aug 2004 18:02:46 -0700, Ramsi <Ra********@hotmail.com> wrote:
Is it possible to disable a image button through the java script?
Thanks for your reply.
Ramsi
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"Ramsi" <Ra********@hotmail.com> wrote in news:egDY$YxhEHA.1344
@TK2MSFTNGP11.phx.gbl:
> 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?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


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=e...8%26oe%3Dutf-8

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

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #7
Ramsi wrote:
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">
Nov 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Sebastian Faust | last post: by
33 posts views Thread by Joe | last post: by
1 post views Thread by dixp | last post: by
7 posts views Thread by perspolis | last post: by
6 posts views Thread by Brian Simmons | last post: by
2 posts views Thread by Joey | last post: by
4 posts views Thread by trullock | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.