我的问题与在带有在 asp.net UpdatePanel 控件中刷新的工具提示的项目上使用 JQuery 工具工具提示插件 ( http://flowplayer.org/tools/tooltip.html ) 有关。问题是,添加工具提示后,来自 UpdatePanel 的任何部分回发都会导致工具提示在任何已更新的 UpdatePanel 中停止工作。工具提示在部分回发之前效果很好。下面是我如何向页面上的图像(和其他控件)添加工具提示的示例。为了简单起见,省略了一些代码:
<script type="text/javascript">
//--call this to add tooltips to any element with a class of "tooltipHandle"
function createTooltip(){
// select all desired input fields and attach tooltips to them
$(".tooltipHandle").tooltip({
// place tooltip on the right edge
position: ['center', 'right'],
// a little tweaking of the position
offset: [-2, 10],
// use a simple show/hide effect
effect: 'toggle',
// custom opacity setting
opacity: 0.7
});
}
//--add tooltips after every postback (including partial AJAX postbacks)
function pageLoad(sender, args) {
createTooltip();
}
</script>
<html>
<!-- assume this UpdatePanel is updated from the code behind--!>
<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="upPanelPrivateMediaList">
<ContentTemplate>
<img class="tooltipHandle" src="/images/questionMark.gif"/>
<div class="tooltip">SOME GREAT TOOLTIP CONTENT</div>
</ContentTemplate>
</asp:UpdatePanel>
</html>
非常有趣的一件事是,如果我在第一次加载页面时不调用“createToolTip()”,则部分回发将正确地将工具提示添加到我的图像中,并且它将一直工作,直到我进行第二次回发。这意味着如果工具提示已经存在,则部分回发只会显示工具提示。在部分回发后手动调用 createToolTip() 不会使工具提示再次工作。
如果您有任何想法或需要澄清,请告诉我。提前致谢!!
最佳答案
您可以将此代码粘贴到正文部分:
<script>
$(document).ready(function () {
$("#demo a[title]").tooltip();
});
</script>
将以下代码粘贴到 .cs 文件中:
protected void Page_Load(object sender, EventArgs e)
{
string javaScriptFunction =
"$(document).ready(function () {" +
"$('#demo a[title]').tooltip()" +
"});";
Page.ClientScript.RegisterStartupScript(typeof(Page), "ajaxTrigger", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);", true);
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "EndRequest", "function EndRequestHandler(sender, args){" + javaScriptFunction + "}", true);
}
关于.net - JQuery 工具工具提示与 UpdatePanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1380876/