Scripting with a UserControl - how to force a refresh?

J

Julian Hayward

I have a page which contains a Windows Forms UserControl and several
DIVs within a table. When the mouse is moved over the UserControl,
it ends up calling the following Javascript:

function Map_mouseMoved()
{
var map = document.getElementById("Map"); // the UserControl
var msg = document.getElementById("Msgbox"); // a DIV

if(map != null)
{
if (msg != null)
{
msg.innerHTML = map.getMessgage();
}
window.status = map.getMessage();
}
}

The getMessage() function returns a string which indicates the mouse
position. What I see when I run it is, when I move the mouse over the
control the text gets written to the status bar every time the mouse
moves by a pixel (OK), but the message DIV only changes when the mouse
enters or leaves the control. I know this function is being called,
so how can I force the browser to refresh the DIV?

The strange thing is, this precise same Javscript worked fine with
a Java applet performing the same task as the UserControl!

Thanks a lot,

Julian
 
B

bruce barker

the div will not update until the next DoEvents loop is called (as the div
update is queued as a windows message). your control could do this after
firing an event.

-- bruce (sqlwork.com)
 
J

Julian Hayward

I had a try, putting the following in my control:

protected override void OnMouseMove(MouseEventArgs e)
{
// Internal stuff that updates the control
foo(e.X, e.Y);
this.Refresh();
// Now fire off an event that javascript can pick up.
if (MapMouseMoved != null)
MapMouseMoved(this, e);
// This should get my DIV updated?
Application.DoEvents();
// don't forget anything in the baseclass handler.
base.OnMouseMove(e);
}

Included in my page is:

<SCRIPT LANGUAGE=javascript FOR=Map EVENT=MapMouseMoved>
<!--
Map_mouseMoved();
//-->
</SCRIPT>

and this function gets called - this is what updates the DIV. But no joy,
it still doesn't update while the mouse is moved over the control. Is this
what you meant, or have I missed something?

Thanks,

Julian
 
B

bruce barker

move Application.DoEvents(); to the end of the function (so its called after
the base calless the javascript routine).

-- bruce (sqlwork.com)
 
J

Julian Hayward

move Application.DoEvents(); to the end of the function (so its called after
the base calless the javascript routine).

Tried that, sadly it made no difference. I'm really confused now!

Julian
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top