服务器控件失去了它的CSS样式时使用更新面板 [英] Server control lost its CSS style when update panel is used

查看:239
本文介绍了服务器控件失去了它的CSS样式时使用更新面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的<一个href=\"http://themeforest.net/item/mango-slick-responsive-admin-template/2728748?sso?WT.ac=category_item&WT.seg_1=category_item&WT.z_author=Stammi\"相对=nofollow>我的项目这模板。我在形式使用的UpdatePanel和更新面板里面我已经asp.net不同的DropDownList控件。现在的问题是,当页面获取回发的CSS样式应用到下拉丢失...
由于我对CSS没有详细的想法。所以请帮助

现在有2个可能性


  • 完全不适用的CSS下拉

  • 回发后申请的CSS下拉

如果我简单地拖放下拉列表控件的形式出现下拉列表的CSS。

我也用这个母版......我不想应用CSS的下拉......怎么办呢..
请建议我...

图片时,页面加载

图片回发后(如果UpdatePanel中使用)

的.aspx code

 &LT; ASP:内容ID =内容2ContentPlaceHolderID =ContentPlaceHolder1=服务器&GT;
  &LT; D​​IV CLASS =S=服务器ID =divError&GT;
        &LT; D​​IV CLASS =圆圆&GT;
            &LT;跨度&GT;
                &所述; IMG ALT =SRC =IMG / Error.png/&GT;
            &LT; / SPAN&GT;&LT;跨度=服务器ID =lblError&GT;&LT; / SPAN&GT;
        &LT; / DIV&GT;
    &LT; / DIV&GT;
    &LT; ASP:的UpdatePanel ID =UpdatePanel1=服务器的UpdateMode =条件RenderMode =内联&GT;
    &LT;&触发器GT;
        &LT; ASP:AsyncPostBackTrigger控件ID =drplstStd/&GT;
    &LT; /触发器&GT;
        &LT;&的ContentTemplate GT;
            &LT; D​​IV CLASS =行动&GT;
                &LT; D​​IV CLASS =左&GT;
                    &LT; ASP:按钮的ID =btnBack=服务器文本=添加新的高度=25像素的OnClick =btnBack_Click/&GT;
                    &LT; BR /&GT;
                    &LT; BR /&GT;
                    &LT; BR /&GT;
                    &LT; ASP:DropDownList的ID =drplstStd=服务器AppendDataBoundItems =真的AutoPostBack =真
                        onselectedindexchanged =drplstStd_SelectedIndexChanged&GT;
                        &LT; ASP:列表项选择=真正的文本= - 选择Standard--VALUE =0&GT;&LT; / ASP:ListItem的&GT;
                    &LT; / ASP:DropDownList的&GT;
                    &LT; BR /&GT;
                     &LT; ASP:DropDownList的ID =drplstSem=服务器&GT;                    &LT; / ASP:DropDownList的&GT;
                    &LT; BR /&GT;
                    &LT; ASP:DropDownList的ID =drplstSubj=服务器AppendDataBoundItems =真&GT;
                        &LT; ASP:列表项选择=真正的文本= - 选择Subject--VALUE =0&GT;&LT; / ASP:ListItem的&GT;
                    &LT; / ASP:DropDownList的&GT;
                    &LT; ASP:文本框ID =txtChapterSearch=服务器&GT;&LT; / ASP:文本框&GT;
                    &LT; ASP:按钮的ID =btnSearch=服务器文本=搜索HEIGHT =25像素的OnClick =btnSearch_Click/&GT;
                &LT; / DIV&GT;
            &LT; / DIV&GT;
            &LT;&字段集GT;
                &LT;传奇&GT;第三章详细信息及LT; /传说&GT;
                &LT; ASP:GridView控件ID =GridView1=服务器的AutoGenerateColumns =FALSEOnRowCommand =GridView1_RowCommand
                    AllowPaging =真OnPageIndexChanging =GridView1_PageIndexChanging每页=10
                    的CssClass =网格的cellpadding =3BORDERCOLOR =#CCCCCC边框宽度=1px的背景色=白
                    边框样式=无&GT;
                    &LT; RowStyle的BackColor =#F6F6F6前景色=#333333/&GT;
                    &LT;柱体和GT;
                        &LT; ASP:的TemplateField的HeaderText =ID可见=假&GT;
                            &LT;&ItemTemplate中GT;
                                &LT; ASP:标签ID =Label1的=服务器文本='&LT;%#绑定(ChapterID)%&GT;'&GT;&LT; / ASP:标签&gt;
                            &LT; / ItemTemplate中&GT;
                            &LT; HeaderStyle宽度=30像素/&GT;
                        &LT; / ASP:的TemplateField&GT;
                        &LT; ASP:的TemplateField的HeaderText =标准&GT;
                            &LT;&ItemTemplate中GT;
                                &LT; ASP:标签ID =Label2的=服务器文本='&LT;%#绑定(标准)%GT;'&GT;&LT; / ASP:标签&gt;
                            &LT; / ItemTemplate中&GT;
                            &LT; HeaderStyle HEIGHT =50像素/&GT;
                            &LT; ItemStyle HEIGHT =25像素/&GT;
                        &LT; / ASP:的TemplateField&GT;
                        &LT; ASP:的TemplateField的HeaderText =学期&GT;
                            &LT;&ItemTemplate中GT;
                                &LT; ASP:标签ID =LABEL3=服务器文本='&LT;%#绑定(学期)%&GT;'&GT;&LT; / ASP:标签&gt;
                            &LT; / ItemTemplate中&GT;
                        &LT; / ASP:的TemplateField&GT;
                        &LT; ASP:的TemplateField的HeaderText =主题&GT;
                            &LT;&ItemTemplate中GT;
                                &LT; ASP:标签ID =Label4=服务器文本='&LT;%#绑定(主题)%GT;'&GT;&LT; / ASP:标签&gt;
                            &LT; / ItemTemplate中&GT;
                        &LT; / ASP:的TemplateField&GT;
                        &LT; ASP:的TemplateField的HeaderText =章&GT;
                            &LT;&ItemTemplate中GT;
                                &LT; ASP:标签ID =Label5=服务器文本='&LT;%#绑定(CHAPTERNAME)%&GT;'&GT;&LT; / ASP:标签&gt;
                            &LT; / ItemTemplate中&GT;
                        &LT; / ASP:的TemplateField&GT;
                        &LT; ASP:的TemplateField的HeaderText =简短&GT;
                            &LT;&ItemTemplate中GT;
                                &LT; ASP:标签ID =Label6=服务器文本='&LT;%#绑定(ChapterSName)%&GT;'&GT;&LT; / ASP:标签&gt;
                            &LT; / ItemTemplate中&GT;
                        &LT; / ASP:的TemplateField&GT;
                        &LT; ASP:的TemplateField ShowHeader =FALSE&GT;
                            &LT;&ItemTemplate中GT;
                                &LT; ASP:LinkBut​​ton的ID =LinkBut​​ton1=服务器的CausesValidation =FALSECommandArgument ='&LT;%#((GridViewRow)集装箱).RowIndex%GT;'
                                    文本=编辑的CommandName =EditDetails&GT;&LT; / ASP:LinkBut​​ton的&GT;
                            &LT; / ItemTemplate中&GT;
                            &LT; ItemStyle WIDTH =100/&GT;
                        &LT; / ASP:的TemplateField&GT;
                        &LT; ASP:的TemplateField ShowHeader =FALSE&GT;
                            &LT;&ItemTemplate中GT;
                                &LT; ASP:LinkBut​​ton的ID =LinkBut​​ton2=服务器的CausesValidation =FALSECommandArgument ='&LT;%#((GridViewRow)集装箱).RowIndex%GT;'
                                    文本=删除的CommandName =DeleteDetails的OnClientClick =如果返回false(window.confirm('你确定要删除这个项目吗?')!);&GT;&LT; / ASP:LinkBut​​ton的&GT;
                            &LT; / ItemTemplate中&GT;
                            &LT; ItemStyle WIDTH =100/&GT;
                        &LT; / ASP:的TemplateField&GT;
                    &LT; /专栏&GT;
                    &LT; FooterStyle背景色=#5D7B9DFONT-粗体=真前景色=白/&GT;
                    &LT; PagerStyle的CssClass =的rowHeaderHorizo​​ntalAlign =中心/&GT;
                    &LT; SelectedRowStyle背景色=#E2DED6FONT-粗体=真前景色=#333333/&GT;
                    &LT; HeaderStyle的CssClass =的rowHeader/&GT;
                    &LT; EditRowStyle背景色=#999999/&GT;
                    &LT; AlternatingRowStyle背景色=#FDFDFD前景色=#284775/&GT;
                &LT; / ASP:GridView的&GT;
             &LT;传奇&GT;
                    &LT; ASP:ImageButton的ID =btnDisplay=服务器的ImageUrl =〜/行政/ IMG / view_refresh.png
                        HEIGHT =16像素WIDTH =16像素的OnClick =btnDisplay_Click/&GT;
                    &LT; ASP:标签ID =lblDisplay=服务器文本=标签&GT;&LT; / ASP:标签&gt;
                &LT; /传说&GT;
            &LT; /字段集&GT;
        &LT; /&的ContentTemplate GT;
    &LT; / ASP:的UpdatePanel&GT;
&LT; / ASP:内容&GT;


解决方案

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

 字符串cssLocalisation =的String.Format(&LT;链接相对= \\样式\\的href = \\{0} \\式= \\文/ CSS \\/&GT ;,RESOLVEURL(YourFile));保护覆盖无效的OnInit(EventArgs的发送)
{
    base.OnInit(E);
    VAR的ScriptManager = ScriptManager.GetCurrent(页);
    如果(!scriptManager.IsInAsyncPostBack)
    {
         ScriptManager.RegisterClientScriptBlock(这的typeof(YourControl),YourKey,cssLocalisation,FALSE);
    }
 }

I am using this template for my project. I have used updatepanel in the form and inside the update panel I have taken different dropdownlist control of asp.net. Now the issue is when the page get post back the css style apply to the dropdown gets lost... As I have no detail idea about the CSS.. So please help

Now there are 2 possibility

  • Not to apply css to the dropdown at all
  • apply CSS to the dropdown after postback

If i simply drag and drop the dropdown control to the form the dropdown appears with the css.

I also used masterpage of this...I don't want to apply css to the dropdown... what to do then.. Please suggest me...

Image when page loads

Image after postback( if updatepanel is used)

.aspx code

<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>

解决方案

You can register your css in OnInit event

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);
    }
 }

这篇关于服务器控件失去了它的CSS样式时使用更新面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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