用户控件的UpdatePanel内 - 更新时,CSS样式都不见了(IE8) [英] User controls inside an UpdatePanel - css styles are gone when updating (IE8)

查看:118
本文介绍了用户控件的UpdatePanel内 - 更新时,CSS样式都不见了(IE8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UpdatePanel内的用户控件。一旦事件被触发,并更新用户控件 - 它似乎失去了它的CSS样式。这发生在我身上只有IE8,而在Chrome和FF感觉不错。

I have an user control inside an UpdatePanel. Once an event is triggered and updates the user control - it seems to lose its css styles. This happened to me in IE8 only, while in Chrome and FF it was fine.

例如用户控件:

<style type="text/css">
    div.test
    {
        width: 500px;
        height: 400px;
        background-color: #0000BB;
        color: #FFFFFF;
        border: 2px solid #11CC00;
    }
</style>
<div id="div123" runat="server" class="test"></div>

public void SetText(string text)
{
     div123.InnerText = text;
}

使用UpdatePanel内的用户控制和更新它的页面:

A page using the user control inside an UpdatePanel and updating it:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <ContentTemplate>
    <div id="div1" runat="server">
        <uc:TestUC ID="test1" runat="server"></uc:TestUC>
     </div>
  <asp:Button ID="Button1" runat="server" OnClick="Button1_OnClick" Text="Click" />
 </ContentTemplate>
</asp:UpdatePanel>

protected void Button1_OnClick(object sender, EventArgs e)
{
     test1.SetText(DateTime.Now.ToString());
}

在Chrome浏览器和FF它似乎是按预期工作(按一下按钮使当前时间在用户控制,没有什么事情发生,以显示),但在IE8的用户控件中的div失去了它的样式(背景颜色,边框)

In Chrome and FF it seems to be working as expected (button click causes current time to display in the user control, nothing else happens), but in IE8 the div inside the user control loses its styles (background color, borders).

什么引起这个问题,什么可以做,以prevent呢?

What could be causing this problem, and what can be done to prevent it?

推荐答案

此问题提到<一个href=\"http://weblogs.asp.net/alessandro/archive/2007/12/31/updatepanel-css-stylesheet-upon-partial-refresh-bug-in-ie.aspx\"相对=nofollow>这里。

我试过的建议 - 注册在OnInit的CSS链接 - 它似乎工作

I tried the suggestion - registering the css link in the OnInit - and it seems to work.

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    ScriptManager sm = ScriptManager.GetCurrent(Page);
    if (!sm.IsInAsyncPostBack)
    {
         string css = string.Format("<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" />", ResolveUrl(CssClassFile));
         ScriptManager.RegisterClientScriptBlock(this, typeof(MyBlahControl), "MyBlahId", css, false);
    }
 }

这篇关于用户控件的UpdatePanel内 - 更新时,CSS样式都不见了(IE8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆