Javascript统一回发
大家下午好,
这是我的情况:
我在母版页中有用户控件,在用户控件中,我可能有一个更新面板。我在用户控件中放置了以下代码,该代码在部分回发期间维护各种控件样式,即受 asp 更新面板影响的控件。
function pageLoad(sender, args) {
if (args.get_isPartialLoad()) {
$("select, span, input").uniform();
事实上,当更新面板完成其任务时,Fancy Dan 样式得以保留。
然而,我有一个抱怨 - 当发生“大”的部分回发时,有时您会看到默认的通用控制样式短暂地重新出现,然后统一开始重新应用新的花哨样式。
有什么方法可以避免看到令人讨厌的旧的、默认的、平淡的样式吗?
任何建议都非常感激。
Good afternoon all
Here is my scenario:
I have user controls within a master page and within a user control, I may have an update panel. I have the following bit of code I place within a usercontrol that maintains various control styling during partial postback i.e. those controls affected within by an asp update panel.
function pageLoad(sender, args) {
if (args.get_isPartialLoad()) {
$("select, span, input").uniform();
Indeed, when an update panel does its thing, the Fancy Dan styling is maintained.
However, I have one gripe - when a 'large' partial postback occurs, occassionally you'll see the default, generic control styling reappear breifly and then the uniform kicks in to reapply the new fancy styles.
Is there any way I can avoid seeing the nasty old, default, bland stylings?
Any suggestions greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看如何使用 PageManagerRequests: MSDN 使用 PageRequestManager
Sys.WebForms.PageRequestManager pageLoading 事件
<前><代码>$(函数() {
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(beautify);
});
函数美化(发送者,eventArgs){
// 如果我们有事件参数
if (eventArgs!= null) {
// 对于每个正在更新的面板,通过添加红色来更新 html
// 选择、跨度、输入元素
// 必须记住调用 .html() 将 html 放回到 panelUpdating[i] 中,否则它会放入 jQuery 对象
for (var i = 0; i < eventArgs.get_panelsUpdating().length; i++) {
//我的测试代码
//var 内容 = eventArgs._panelsUpdating[i].outerHTML;
//var jContent = $(内容);
//$("输入", jContent).css("颜色", "红色");
//jContent = $('
//var jContentToContent = jContent.html();
//警报(jContentToContent);
//eventArgs._panelsUpdating[i].outerHTML = jContentToContent;
}
编辑: 我认为您明白问题是元素之前被放置到 DOM 中(因此被绘制)你的 javascript 有机会使它们统一()。这会拦截 UpdatePanel 和 Uniform() 的代码,然后将其插入 DOM
Edit 2 好吧,我已经更新了很多,我用我的测试代码对其进行了测试,然后包含了您可能添加的代码。另外,我在 eventArgs._panelsUpdating 中走了捷径 - 我真的应该使用 get 和 set 函数,但这可行。
Check out working with PageManagerRequests: MSDN Working With PageRequestManager
Sys.WebForms.PageRequestManager pageLoading Event
Edit: I think you understood that the issue was the elements were being placed into the DOM (and therefore painted) before your javascript had a chance to make them uniform(). This intercepts the UpdatePanel and uniform()'s the code prior to it inserted into the DOM
Edit 2 Alright, I've updated it a bunch, I tested this with my test code there and then included the code you're likely to add. Also, I took a short cut in eventArgs._panelsUpdating - i should really be using the get and set functions, but this works.