Wednesday, March 28, 2012

change mouse pointer on AJAX UPDATE

i can't understand why i do same page exacly the same (copy & past) and sometimes it worked OK sometime it said javascript error.

My goal is to Change mouse pointer while AJAX is updating something and after finishes to change it back. I have found some woderfull example

please take a look at it:

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<scriptlanguage="javascript"type="text/javascript">

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_initializeRequest(InitializeRequest);

prm.add_endRequest(EndRequest);

function InitializeRequest(sender, args)

{

$get('Container').style.cursor ='wait';

// Get a reference to the element that raised the postback,

// and disables it.

$get(args._postBackElement.id).disabled =true;

}

function EndRequest(sender, args)

{

$get('Container').style.cursor ='auto';

// Get a reference to the element that raised the postback

// which is completing, and enable it.

$get(sender._postBackSettings.sourceElement.id).disabled =false;

}

</script>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:LabelID="Label1"runat="server"Text="Update Me"></asp:Label>

<br/>

<br/>

<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/>

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</body>

</html>

whats wrong here?

hello.

well, i think that the code you've written will only change the cursor when it's over the container html control. btw, i'm not finding that control on the page you've posted...


well it worked few times. Here is a link to the original sample:

http://encosia.com/2007/01/01/improved-progress-indication-with-aspnet-ajax/

look at it and maybe it will be more clearer what i am up to


hello.

well, but in the case of that sample, the complete form is wrapped by a div element which is named container (and that's why the cursor changes with the previous code)...


ok so what would be my solution not nesceserily this particular one but i have an AJAX based website with master page and multiple content pages and i need

notify user when ajax completes any given task Best and many years know way is to change mouse cursor How can i do that besides this example? or maybe it needs some corrections?


hello.

i haven't run the example, but i think it's working. what i'm trying to tell you is that you're missing a div. if you look at the sample, you should see that the first child of the body is a div element named container. when you start a partial postback, it'll change the cursor for that element. since it is the top element, that means that while the mouse cursor is over the space ocuppied by the div, you'll see that cursor during a partial postback. since you don't have this div in the code you've shown, i'm assuming that it simply doesn't work.

you must keep in mind is that you'll only see that cursor when the mouse is OVER that element!


Thank you very much


one more thing i would like to ask you Now i put my master page in div with specified tag So if press any button it changes mouse cursor but if i hover onto a other button or textbox it changes cursor to default state only if am hovering onto label or sometext data i can see hourglass How can do that if something is going on no matter where you put your mouse on the DIV container the cursor still would be a hourglass?

No comments:

Post a Comment