Reputation: 75
There are a couple places throughout my web app where things will lose the css attached to them. One such instance is where I have a label that populates from a database value, and has a linkbutton next to it that makes the label visible = false, and then a DDL that is initially invisible becomes visible(so that you can edit the field). This DDL doesn't have any of the css attached to it, and is just a blank white box where you can only see the value you have highlighted. However if I start the same DDL off as visible, it has the css just fine. Here is the code for that:
<asp:DropDownList class="ddl" runat="server" Width="100%" ID="Status_DDL" Visible ="false">
<asp:ListItem>Dropped</asp:ListItem>
<asp:ListItem>Redirected</asp:ListItem>
<asp:ListItem>Tracked-Closed</asp:ListItem>
<asp:ListItem>On-Hold</asp:ListItem>
<asp:ListItem>Roadmap</asp:ListItem>
<asp:ListItem>Strategy</asp:ListItem>
<asp:ListItem>Unknown</asp:ListItem>
<asp:ListItem>Completed</asp:ListItem>
<asp:ListItem>In Progress</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" CssClass="Text-Dates" ID="StatusLabel"></asp:Label>
And then the code behind is just Status_DDL.Visible = true and StatusLabel.Visible = false.
Another time it happens is on dropdown lists where things change based on what value is selected. Sometimes it will just lose the css and revert to an ugly DDL.
Thanks!
Edit: Here are images of what it looks like:
And what it is supposed to look like, and does look like if I start it off with the ddl visible and label invisible:
Upvotes: 0
Views: 111
Reputation: 865
That's a well known problem with updatePanel, and partial postbacks. Apparently the solution (it worked for me) was to move the css to the header of the page. There is a way to link it if you're using masterpages, or your dropdownlist is in a web control. More info at this answer.
Upvotes: 0
Reputation: 123
With ASP native controls you have to use "CssClass" attribute not "class", so the correct form is :
<asp:DropDownList CssClass="ddl" runat="server" Width="100%" ID="Status_DDL" Visible ="false">
Upvotes: 2