Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make the mouse pointer an hourglass 8

Status
Not open for further replies.

christheprogrammer

Programmer
Jul 10, 2000
258
CA
Anyone ever done this on a webform? When a query is being performed, it would be nice to make the mouse pointer an hourglass...

Cheers Chris
 
Hey Chris,

It is possible, but it requires some know-how of CSS to do it (which i unfortunatley have little know-how about, newbie in that department).

You might want to try and post something in the HTML and CSS forum and see if anyone there can point you in the right direction.
:)

Jack
 
Hey bud,

You can do this in html(css) with 'style="cursor:wait"' so I'm not exactly sure what you would want to do but you could apply it to an html element with javascript like: 'this.style.cursor="wait"'.

I'm not too sure how you would go about mixing this with your ASP but hope this gives you something to work with.

P.S I think this is only an I.E thing too. [smurf]
01101000011000010110010001110011
 
in the head of your aspx file, simple put this in and change btnName to the name of your button

<SCRIPT LANGUAGE=&quot;vbscript&quot;>
<!--
Sub btnName_onclick
document.body.style.cursor = &quot;wait&quot;
End Sub
-->
</SCRIPT>

the only problem is possibly with mixing vbscript and javascript code on the client.

there's probably a better way to do this, like register a script for the client click on the button to call a javascript function with the same thing, but vbscript event handlers don't need an onclick=&quot;&quot; attribute of the triggering element to fire....the script automatically pools the page and waits for the button to be clicked. mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
another idea...

document.getElementById(&quot;btnName&quot;).setAttribute(&quot;value&quot;,&quot;Please Wait...&quot;)

this could also be in there too...it'll change the button's text to &quot;please wait...&quot;

anyone thinking about a custom submit button control??

mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
Thanks, Mike,
I think I will have to do the label thing (&quot;Please wait while your query is processed&quot;) or something. It would be nice to do the hourglass thing, but I am facing time constraints now... Thanks a bunch though!

If anyone does know how to make the mouse pointer an hourglass when the user presses a server control asp button please post - I could easily add it later to my project...
TIA Chris says: &quot;It's time for a beer.&quot;
 
here you go....try this as the codebehind for a user control

----------------------------------------------

using System;
using System.Web;
using System.Web.UI;
using System.Text;

namespace truck_sales_and_service
{
/// <summary>
/// Summary description for WaitingButton.
/// </summary>
public abstract class WaitButton : System.Web.UI.UserControl
{
protected string _Text;
protected string _ClassName;

public string Text
{
get { return _Text; }
set { _Text = value; }
}

public string ClassName
{
get { return _ClassName; }
set { _ClassName = value; }
}

protected override void OnPreRender (EventArgs e)
{
Page.RegisterClientScriptBlock (
&quot;__doAlert&quot;,
&quot;<script language=\&quot;javascript\&quot;>\n&quot; +
&quot;<!--\n&quot;+
&quot;function __doWait (btnWaiter)\n&quot; +
&quot;{\n&quot; +
&quot; btnWaiter.setAttribute(\&quot;value\&quot;,\&quot;Please Wait...\&quot;);\n&quot; +
&quot; document.body.style.cursor=\&quot;wait\&quot;;\n&quot; +
&quot;}\n&quot; +
&quot;-->\n&quot;+
&quot;</script>&quot;
);
}

protected override void Render (HtmlTextWriter writer)
{
StringBuilder builder = new StringBuilder ();

builder.Append (&quot;<input type=\&quot;submit\&quot; value=\&quot;&quot;);
builder.Append (_Text);
builder.Append (&quot;\&quot; onclick=\&quot;javascript:__doWait (this);\&quot;&quot;);
if (_ClassName != null)
{
builder.Append(&quot; class=\&quot;&quot;);
builder.Append(_ClassName);
builder.Append(&quot;\&quot;&quot;);
}
builder.Append (&quot;/>&quot;);

writer.Write (builder.ToString ());
}
}
}


--------------------------------------------

then

<%@ Register TagPrefix=&quot;mdg12&quot; TagName=&quot;WaitingButton&quot; Src=&quot;WaitingButton.ascx&quot; %>
<form runat=&quot;server&quot;>
<msg12:WaitingButton text=&quot;hello&quot; runat=&quot;server&quot; />
</form> mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
Thanks Mike, I have never made a user control before, so this will take a bit of time. I'll post back when I figure it all out to let you know if it worked or not Chris says: &quot;It's time for a beer.&quot;
 
I have a button named cmdReport. In my aspx.vb file's Page_Load sub I put this :
cmdReport.Attributes(&quot;onclick&quot;) = &quot;javascript: hourglass();&quot;

Then in the <HEAD> of my .aspx file I put this:
<script language=&quot;javascript&quot;>
function hourglass()
{
document.body.style.cursor = &quot;wait&quot;;
}
</script>

Works great for me and it's simple.

Shanti
 
and yes, it's a server control button. I couldn't figure out a way to add the onclick attribute without adding that code to the Page_Load sub. I kept getting errors trying to manually add an onclick to the html for the asp:button. But with the way I showed above, it worked fine.
 
Shanti:
This works so well, it is going in my bag of tricks.
Thanks a million! Life is like a box of chocolates, sweet
 
millerk, you should FAQ this.

would make a very nice addition.
penny1.gif
penny1.gif
 
millerk, the hourglass part works great after a button click etc, but now the cursor shows up as a hourglass (even after post back ) when I hover it over the other controls on the page ( ex Labels)... though it shows up as a normal pointer hovering over the the button .

..what might be causeing this?
 
Wow. Two year later, I don't even remember what app I used this for. I really don't do much web programming so I can't really help you.

Hopefully someone will have an answer for you.
 
It looks as if after setting the cursor to "wait", there's nothing to trigger it to go back to "default", though I am not sure as I've never tinkered with cursors like this.

Try calling this code when you see fit:


function backtonormal()
{
document.body.style.cursor = "default";
}
 
Yeah, I think in the app where I used that, clicking the button did some processing, then went to another page. That may be the reason I didn't have that issue.
 
BoulderBum, how do i "call" the java script code??
I use this to call it for the hourglass thing
mybutton.Attributes.Add("onclick", "javascript:hourglass();");

but this is event based ( onclick), how do I call the backtonormal () script assuming It shoudl be called on page postback?

(using C#)

thx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top