我有一个带有 asp:Button
和 asp:TextBox
的 asp:UpdatePanel
:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button runat="server" Text="Click" ID="button" onclick="button_Click"/>
<asp:TextBox runat="server" Title="Text" ID="text" Style="margin-top: 50px;" />
</ContentTemplate>
</asp:UpdatePanel>
button_Click
方法是:
protected void button_Click(object sender, EventArgs e) {
text.Attributes.Add("title", "Box");
ClientScript.RegisterClientScriptBlock(typeof(ScriptManager), "Tooltify", "tooltipfy();", true);
}
tooltify()
是一个 javascript 函数。
var tooltipfy = function () {
alert('');
$('[title]').qtip({
style: {
tip: {
corner: true,
width: 10,
height: 5
},
classes: 'ui-tooltip-rounded ui-tooltip-shadow ui-tooltip-tipsy'
},
position: {
my: 'bottom left',
at: 'top right',
adjust: {
x: -10,
y: 0
}
},
events: {
show: function (event, api) {
$('.ui-tooltip-content').addClass('ui-tooltip-center');
}
},
show: {
effect: function (offset) {
$(this).show("slide", { direction: "up" }, 500);
}
},
hide: {
effect: function (offset) {
$(this).hide("explode", 500);
}
}
});
}
问题是函数没有执行。
如何在使用 asp:UpdatePanel
时调用 JavaScript 函数?
最佳答案
在使用 UpdatePanel
时,您应该使用 ScriptManger
。
protected void button_Click(object sender, EventArgs e) {
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),"Tooltify", "tooltipfy();", true);
}
关于c# - ASP :UpdatePanel - Add JavaScript on Button Click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9958515/