How can I add a css class to an updatepanel in the c# code behind file of asp.net
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
HTML
CSS
You could also do as I have and just create a new class that inherits the UpdatePanel. I got the basis for this somewhere else but I don't remember where so I can't credit fully but I only tweaked it for this idea. I'm about to do the same for HTML Attributes (since the .attributes() collection is for css on the UpdatePanel instead of raw HTML attributes as with most other web.ui.controls).
UPDATED: I've updated to include some other customization I've made that allow for ANY attribute to be added. Really this duplicates the first customization except that the 1st creates a fairly standard approach where this is completely flexible (thus not standard).
C# conversion via http://www.developerfusion.com/:
An update panel can render as a div or span (depending on mode). Easiest way to achieve what you want is to wrap the UpdatePanel in a standard Panel:
The you can just do this in codebehind:
You could also use a div, like LFSR Consulting said, and add
runat="server"
and then change the class attribute. But Panel is a bit easier to work with (a Panel just renders as a div).CodeBehind:
HTML Result:
As you've seen the update panel doesn't have a css class property. So since it can't be done directly you need a work around; there are two (Grabbed from UpdatePanel and CSS) that can get the behavior you desire.
One is to surround the update panel with a div:
The other is to apply a css selector based on the update panel's id:
Yet another way not mentioned in the article is surround the panel in a div and style the update panel based on it rendering as a div:
you can use single class html attribute