It sounds like you're using a master page, right? Where is the ScriptManager? (Master or content?)
Could you maybe show us your code?
It sounds like you're using a master page, right? Where is the ScriptManager? (Master or content?)
Could you maybe show us your code?
I have manged to get a little further on this, by calling registerStartupScript, but Im still having issues with it. The script manager is in the master page.
<asp:Content Visible="false" ID="Content1" ContentPlaceHolderID="PageBody" runat="server">
<asp:ScriptManagerProxy ID="ProxyManager" runat="server">
<Scripts>
<asp:ScriptReference NotifyScriptLoaded="true" Path="~/Products/ViewDocument.js" ScriptMode="Auto" />
</Scripts>
</asp:ScriptManagerProxy>
<table border="1">
<tr>
<td valign="top">
<div style="OVERFLOW: scroll; POSITION: static; HEIGHT: 500px; WIDTH: 1000px;">
<asp:UpdatePanel ID="MapPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ImageMap ID="ImageMap" HotSpotMode="Navigate" runat="server" ImageUrl="http://E13184.TIF.gif" BorderWidth="0" OnClick="ImageMap_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="ProductInformation">
<asp:UpdatePanel runat="server" ID="PartInformationPanel" UpdateMode="Conditional">
<ContentTemplate>
<table border="0" cellpadding="0" cellspacing="2">
<tr class="ItemDescription">
<td>Item</td>
<td><asp:Label runat="server" ID="uiPartItem" /></td>
</tr>
</table
</ContentTemplate>
</asp:UpdatePanel>
</div>
</td
<td valign="top">
Ipsem lorem...
</td>
</tr>
</table>
</asp:Content>
The javascript referenced by the script manager proxy:
var postBackElement;
var clientClickX;
var clientClickY;function setClickPosition(e)
{
clientClickX = e.clientX;
clientClickY = e.clientY;
}function ImageMapBegin()
{
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadComplete);
addClickHandlerForImageMap();
}function beginRequest(sender, args)
{
postbackElement = args.get_postBackElement();
if (postbackElement.id.toLowerCase().indexOf('ImageMapctl00_PageBody_ImageMap') > -1)
{
$clearHandlers($get('ImageMapctl00_PageBody_ImageMap'));
}
}function pageLoadComplete(sender, args)
{
var updatedPanels = args.get_panelsUpdated();
if (typeof(postbackElement) === "undefined")
{
return;
}
else if (postbackElement.id.toLowerCase().indexOf('ImageMapctl00_PageBody_ImageMap') > -1)
{
alert(1);
setDivPosition();
addClickHandlerForImageMap();
}
}function setDivPosition()
{
var div = $get('ProductInformation');
div.style.display = "block";
div.style.top = clientClickY + 10 + "px";
div.style.left = clientClickX + 10 + "px";
}function addClickHandlerForImageMap()
{
alert('add click handler');
var e = document.getElementsByName("ImageMapctl00_PageBody_ImageMap")[0];
$addHandler(e, "click", setClickPosition);
}if(typeof(Sys) != 'undefined') Sys.Application.notifyScriptLoaded();
And in the code behind, I have added a function to call ImageMapBegin
protected override void OnPreRender(EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(),"IMAGEMAPSCRIPT","ImageMapBegin();",true);
}
Thanks for your help!
Joe
After walking through this in Fiddler and Firebug, it looks as though all of the ajax-y bits are working ok. The problem now is that the code in the pageLoadComplete is not running... In Firebug i can set a breakpoint on the "setDivPosition" call in the pageLoadComplete event, and the breakpoint is hit, but when I try and step into it, the debugger jumps into the Microsot scripts.
Here is what I have
function pageLoadComplete(sender, args) { var updatedPanels = args.get_panelsUpdated(); if (typeof(postbackElement) === "undefined") { return; } else if (postbackElement.id.toLowerCase().indexOf('ImageMapctl00_PageBody_ImageMap') > -1) { setDivPosition(); addClickHandlerForImageMap(); } } function setDivPosition() { alert('setDiv'); } function addClickHandlerForImageMap() { alert('add click handler'); } And here is the function that is being called when I step into code from my breakpoint (always on line 12)
1function Sys$EventHandlerList$getHandler(id) {2 var e = Function._validateParams(arguments, [{name:"id", type:String}]);3 if (e) {4 throw e;5 }6 var evt = this._getEvent(id);7 if (!evt || evt.length === 0) {8 return null;9 }10 evt = Array.clone(evt);11 if (!evt._handler) {12 evt._handler = function (source, args) {for (var i = 0, l = evt.length; i < l; i++) {evt[i](source, args);}};13 }14 return evt._handler;15}Thanks
Joe
The solution as usual: look like a moron in public, then spot your obvious mistake.
function pageLoadComplete(sender, args) { var updatedPanels = args.get_panelsUpdated(); if (typeof(postbackElement) === "undefined") { return; } else if (postbackElement.id.toLowerCase().indexOf('ctl00_pagebody_imagemap') > -1) { setProductInfoPosition(); addClickHandlerForImageMap(); } }Note to self: When you say toLowerCase(), make sure the string you are comparing is also lowercase.:-)
No comments:
Post a Comment