Showing posts with label mouse. Show all posts
Showing posts with label mouse. Show all posts

Monday, March 26, 2012

How do I change mouse pointer for DragPanelExtender?

Hello,

I have DetailsView inside UpdatePanel, when I hover my mouse over title it changes mouse cursor like I'm trying to type something )(

How can I prevent this or what is the best way to give that panel "draggable" look? Also how do I automatically position this window next to specific button on my HTML form?

Thanks,

It seems like you could do this by applying the CSS cursor property to the relevant parts of your page:http://www.w3.org/TR/CSS21/ui.html#cursor-props.

Wednesday, March 21, 2012

How can I reset the AJAX Timer component if the mouse is moved!

I have a few pages that use UpdatePanels and Timer components to refresh the content periodically. However I need to have it refresh only when the mouse hasn't been moved for a minute so it doesn't interrupt the user.

I have been using a javascript timer to refresh a custom component that uses callbacks but it is interfering with the AJAX UpdatePanel and causing State Corruption so I would like an all AJAX solution if possible.

Question 1: Can mouse movement reset an Ajax Timer, if so how?

Question 2: Is there a way to trigger the UpdatePanel from Javascript?

1. Use the method show here to get a refrence to the behavior for the timer, thenhttp://ajax.asp.net/docs/ClientReference/Sys.UI/BehaviorClass/BehaviorGetBehaviorsByName.aspx, call

Sys$UI$_Timer$_stopTimer & then this

Sys$UI$_Timer$_startTimer

Not sure if that will work exactly, but, through that or somthing similar you should be able to manipulate the timer on the client side.

2. Take a look at this post, it has a few differnt examples of how to do an update from javascript:http://forums.asp.net/thread/1541012.aspx


Thanks for the help there. I now need to figure out which behaviour name to look for in the timer, i guess?


Easily referencing behavior instances

It used to be tricky to get a reference to a behavior from client script, but now you can simply add a "BehaviorID" attribute to your control's property specification and it will be easily accessible on the client via ASP.NET AJAX's Sys.Application.findComponent(id) method or its $find(id) shortcut. (Note: If BehaviorID isn't specified, the behavior's ID on the client will be the same as the extender control's ClientID.) See DynamicPopulate or ResizableControl for examples.


I guess I should have added... that its used for the AJAX toolkit, so you might not be able to specify the BehaviorID, but you still should be able to get it with the find method.

I have tried the following code but it doesn't change the timer, it still goes off after a minute:

code = "function MainMenuPage_onmousemove(){"
code += " var b = $find('" & MT.ClientID & "');"
code += " if(b){"
code += " mouse_moved=1;"
code += " b.Sys$UI$_Timer$_stopTimer;"
code += " b.Sys$UI$_Timer$_startTimer;"
code += " }"
code += "}"

Please excuse the code formatting above (I create strings of the code snippets I need for the page and then useRegisterClientScriptBlock)

I'm not receiving any Javascript errors when I move the mouse. I know it's finding MT.ClientID as I use another javascript timer to display the mouse_moved variable. Perhaps I'm not changing the actual instance of the timer? Wild guess here. I really need to have more time to study the nitty gritty bits of AJAX but as it is I hardly have time to do this much.

I appreciate your time on this. I hope you have more bright ideas because I'm fresh out.


I tested the below code & it seems to workCool ... notice how i removed the Sys$UI$_Timer$ from the method call and added a () at the end
 code ="function MainMenuPage_onmousemove(){"; code +=" var b = $find('" + Timer1.ClientID +"');"; code +=" if(b){"; code +=" mouse_moved=1;"; code +=" b._stopTimer();"; code +=" b._startTimer();"; code +=" }"; code +="}";

Awesome. That worked.

Thank you very much.

How can I prevent floatingBehavior being draggable via the right mouse button?

Hi there,

I'd like to be able to handle a right-click in a region that has the floatingBehavior. Unfortunately, the fact that floatingBehavior allows the region to be dragged via the right (context) mouse button as well as the left is interfering. (In fact, even if it weren't causing problems for me, having the regions draggable by the right mouse button breaks a lot of the UI conventions I'm hoping to capitalise on.)

So, I'd like to stop the right mouse button from dragging. How can I do this?

There's no built-in option, but that's OK. I'm happy to inherit and override the floatingBehavior class, but the important bits don't seem to be overridable (unless I'm doing it wrong) and anyway floatingBehavior is sealed.

How can I accomplish this?

Many thanks,

Geoff

1. You can't inherit from the class and would have to rewrite it. I WISH!!!
2. Button definition within browser means different things on different browsers, systems, no real way to tell which button was pressed.
3. If you write your own you can do this only for some of the browsers and os. From memory button and which returns 0 on some browsers for left, on some it returns 1, no real way to tell which is clicked for all browsers.
4. Whatever you're trying to capitalize on assumes there is more than 1 button. What abour our Mac friends? (ahem, I admit it I use a Mac on occassion).


Hi,

1:. I was afraid of that.

2, 3 and 4: I'm not convinced. The DOM specifies the button used for events (http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MouseEvent-button) and says how to handle buttons being swapped etc. And isn't one of the main drivers of Atlas being able to abstract away browser differences?

Fundamentally though I just don't think allowing drags by any button other than the left one is proper for many UIs. For instance, you can't drag the browser window in XP by grabbing the title bar with the right mouse button. You can't drag and drop messages in Outlook with the right mouse button. You can't drag and drop text in this very edit control with the right mouse button. All those actions only work with the left mouse button (with the right mouse button operating a context menu sometimes). I just want to be consistent with those expected behaviors.

I'm not against writing code to solve this, I'd just rather not have to reimplement the whole floatingBehavior for this one change.

Geoff


Like I said you won't be able to do this for every browser in every type of event. Here's a snippet that works for most browsers but I would only use it if you have strict requirements. I would also be careful about referring to buttons as left and right as some operating systems give you the option to switch left and right button (think left handed users) so better names are primary, secondary. The tertiary is either the 3rd button or the mouse wheel, no real definition here. Here's what you'd use inside your event.

var btn = Event.Which(e);
if (btn != Button.Primary) return;

Type.createEnum('Button','None', 0,'Primary', 1,'Secondary', 2,'Tertiary', 3);


Type.registerNamespace('Event');
Event.Which =function(e) {
if (typeof(e) =='undefined') e = window.event;
var isIE =(Sys.Runtime.get_hostType() == Sys.HostType.InternetExplorer); if (isIE ? (event.button & 1) > 0 : (event.button==1 ||event.which==1))return Button.Primary;
if (isIE ? (event.button & 2) > 0 : (event.button==3 ||event.which==3))return Button.Secondary;
if (isIE ? (event.button & 4) > 0 : (event.button==2 ||event.which==2))return Button.Tertiary;

return Button.None;
}