Ajax 更新面板和样式
我有一个用 js 和 css 设计的按钮,每次我单击该按钮(进行回发)时,它都会在更新面板内,它会失去样式吗?
很确定这是一个简单的问题,知道吗?
<html xmlns="http://www.w3.org/1999/xhtml">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" class="art-button" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
function artButtonsSetupJsHover(className) {
var tags = ["input", "a", "button"];
for (var j = 0; j < tags.length; j++){
var buttons = xGetElementsByClassName(className, document, tags[j]);
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
if (!button.tagName || !button.parentNode) return;
if (!artHasClass(button.parentNode, 'art-button-wrapper')) {
if (!artHasClass(button, 'art-button')) button.className += ' art-button';
var wrapper = document.createElement('span');
wrapper.className = "art-button-wrapper";
if (artHasClass(button, 'active')) wrapper.className += ' active';
var spanL = document.createElement('span');
spanL.className = "l";
spanL.innerHTML = " ";
wrapper.appendChild(spanL);
var spanR = document.createElement('span');
spanR.className = "r";
spanR.innerHTML = " ";
wrapper.appendChild(spanR);
button.parentNode.insertBefore(wrapper, button);
wrapper.appendChild(button);
}
artEventHelper.bind(button, 'mouseover', function(e) {
e = e || window.event;
wrapper = (e.target || e.srcElement).parentNode;
wrapper.className += " hover";
});
artEventHelper.bind(button, 'mouseout', function(e) {
e = e || window.event;
button = e.target || e.srcElement;
wrapper = button.parentNode;
wrapper.className = wrapper.className.replace(/hover/, "");
if (!artHasClass(button, 'active')) wrapper.className = wrapper.className.replace(/active/, "");
});
artEventHelper.bind(button, 'mousedown', function(e) {
e = e || window.event;
button = e.target || e.srcElement;
wrapper = button.parentNode;
if (!artHasClass(button, 'active')) wrapper.className += " active";
});
artEventHelper.bind(button, 'mouseup', function(e) {
e = e || window.event;
button = e.target || e.srcElement;
wrapper = button.parentNode;
if (!artHasClass(button, 'active')) wrapper.className = wrapper.className.replace(/active/, "");
});
}
}
}
artLoadEvent.add(function() { artButtonsSetupJsHover("艺术按钮"); });
I have a button styled with js and css and its inside an update panel everytime i click the button (do postback) it loses style ?
pretty sure its an easy issue here , any idea ?
<html xmlns="http://www.w3.org/1999/xhtml">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" class="art-button" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
function artButtonsSetupJsHover(className) {
var tags = ["input", "a", "button"];
for (var j = 0; j < tags.length; j++){
var buttons = xGetElementsByClassName(className, document, tags[j]);
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
if (!button.tagName || !button.parentNode) return;
if (!artHasClass(button.parentNode, 'art-button-wrapper')) {
if (!artHasClass(button, 'art-button')) button.className += ' art-button';
var wrapper = document.createElement('span');
wrapper.className = "art-button-wrapper";
if (artHasClass(button, 'active')) wrapper.className += ' active';
var spanL = document.createElement('span');
spanL.className = "l";
spanL.innerHTML = " ";
wrapper.appendChild(spanL);
var spanR = document.createElement('span');
spanR.className = "r";
spanR.innerHTML = " ";
wrapper.appendChild(spanR);
button.parentNode.insertBefore(wrapper, button);
wrapper.appendChild(button);
}
artEventHelper.bind(button, 'mouseover', function(e) {
e = e || window.event;
wrapper = (e.target || e.srcElement).parentNode;
wrapper.className += " hover";
});
artEventHelper.bind(button, 'mouseout', function(e) {
e = e || window.event;
button = e.target || e.srcElement;
wrapper = button.parentNode;
wrapper.className = wrapper.className.replace(/hover/, "");
if (!artHasClass(button, 'active')) wrapper.className = wrapper.className.replace(/active/, "");
});
artEventHelper.bind(button, 'mousedown', function(e) {
e = e || window.event;
button = e.target || e.srcElement;
wrapper = button.parentNode;
if (!artHasClass(button, 'active')) wrapper.className += " active";
});
artEventHelper.bind(button, 'mouseup', function(e) {
e = e || window.event;
button = e.target || e.srcElement;
wrapper = button.parentNode;
if (!artHasClass(button, 'active')) wrapper.className = wrapper.className.replace(/active/, "");
});
}
}
}
artLoadEvent.add(function() { artButtonsSetupJsHover("art-button"); });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能在 onload 事件中设置 js 中的样式,但该事件仅触发一次,然后在每次回发中更新面板不会通过它。您必须像这样附加到 PageRequestManager pageloaded 事件:
在 ScriptManager 声明之后,您编写此代码,并且每次在内部进行回发时脚本都会运行。
或者直接从 Sys.Application.add_load :
You are probably setting the style in js in the onload event, but this event is only fired once and then in every postback the update panel does not pass through it. You have to attach to the PageRequestManager pageloaded event like this:
After the ScriptManager declaration you write this code and the script will run each time you do a postback inside.
Or directly from Sys.Application.add_load:
在某些情况下,我可以想到
.如果您给我们代码也许我们可以看到问题所在。
There are some cases that I can think of
.If you give us the code maybe we can see whats the problem.
如果您使用 js 设置样式,则可能需要在页面上的 ScriptManager 中注册该 js。这样脚本将在部分页面回发时加载。
If you're setting styles with js, you may need to register that js with the ScriptManager on the page. That way the script will be loaded on partial page postbacks.