微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 使用更新面板时,服务器控件丢失了CSS样式

我正在为我的项目使用 this模板.我在表单和更新面板中使用了updatepanel,我采用了不同的asp.net下拉列表控件.现在的问题是当页面回发后,css样式适用于下拉列表丢失…
因为我没有关于CSS的详细信息..所以请帮助

现在有2种可能性

>根本不要将css应用于下拉列表
>在回发后将CSS应用于下拉列表

如果我只是将下拉控件拖放到表单,则下拉列表会显示css.

我也使用了这个的主页…我不想将css应用于下拉列表…该怎么办呢…
请建议我……

页面加载时的图像

回发后的图像(如果使用updatepanel)

.aspx代码

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
  <div class="s" runat="server" id="diverror">
        <div class="round">
            <span>
                <img alt="" src="img/Error.png" />
            </span><span runat="server" id="lblError"></span>
        </div>
    </div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Inline">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="drplstStd" />
    </Triggers>
        <ContentTemplate>
            <div class="actions">
                <div class="left">
                    <asp:Button ID="btnBack" runat="server" Text="Add new" Height="25px" OnClick="btnBack_Click" />
                    <br />
                    <br />
                    <br />
                    <asp:DropDownList ID="drplstStd" runat="server" AppendDataBoundItems="true" AutopostBack="true"
                        onselectedindexchanged="drplstStd_SelectedindexChanged">
                        <asp:ListItem Selected="True" Text=" --Select Standard-- " Value="0"></asp:ListItem>
                    </asp:DropDownList>
                    <br />
                     <asp:DropDownList ID="drplstSem" runat="server">

                    </asp:DropDownList>
                    <br />
                    <asp:DropDownList ID="drplstSubj" runat="server" AppendDataBoundItems="true">
                        <asp:ListItem Selected="True" Text=" --Select Subject-- " Value="0"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:TextBox ID="txtChapterSearch" runat="server"></asp:TextBox>
                    <asp:Button ID="btnSearch" runat="server" Text="Search" Height="25px" OnClick="btnSearch_Click" />
                </div>
            </div>
            <fieldset>
                <legend>Chapter details </legend>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"
                    AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="10"
                    CssClass="grid" CellPadding="3" BorderColor="#CCCCCC" BorderWidth="1px" BackColor="White"
                    BorderStyle="None">
                    <RowStyle BackColor="#F6F6F6" ForeColor="#333333" />
                    <Columns>
                        <asp:TemplateField HeaderText="Id" Visible="False">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("ChapterID") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle Width="30px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Standard">
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Standard") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle Height="50px" />
                            <ItemStyle Height="25px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Semester">
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%# Bind("Semester") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Subject">
                            <ItemTemplate>
                                <asp:Label ID="Label4" runat="server" Text='<%# Bind("Subject") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Chapter">
                            <ItemTemplate>
                                <asp:Label ID="Label5" runat="server" Text='<%# Bind("ChapterName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="ShortForm">
                            <ItemTemplate>
                                <asp:Label ID="Label6" runat="server" Text='<%# Bind("ChapterSName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument='<%#((GridViewRow)Container).RowIndex%>'
                                    Text="Edit" CommandName="EditDetails"></asp:LinkButton>
                            </ItemTemplate>
                            <ItemStyle Width="100" />
                        </asp:TemplateField>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandArgument='<%#((GridViewRow)Container).RowIndex%>'
                                    Text="Delete" CommandName="DeleteDetails" OnClientClick="if (!window.confirm('Are you sure you want to delete this item?')) return false;"></asp:LinkButton>
                            </ItemTemplate>
                            <ItemStyle Width="100" />
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle CssClass="rowheader" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle CssClass="rowheader" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="#FDFDFD" ForeColor="#284775" />
                </asp:GridView>
             <legend>
                    <asp:ImageButton ID="btndisplay" runat="server" ImageUrl="~/Admin/img/view_refresh.png"
                        Height="16px" Width="16px" OnClick="btndisplay_Click" />
                    <asp:Label ID="lbldisplay" runat="server" Text="Label"></asp:Label>
                </legend>
            </fieldset>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

解决方法

您可以在OnInit事件中注册您的CSS

string cssLocalisation  = string.Format("<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" />",ResolveUrl(YourFile));

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    var scriptManager = ScriptManager.GetCurrent(Page);
    if ( ! scriptManager.IsInAsyncPostBack)
    {
         ScriptManager.RegisterClientScriptBlock(this,typeof(YourControl),"YourKey",cssLocalisation,false);
    }
 }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐