ASP.NET: Create new CSS class programmatically from User Control? -
i have usercontrol contains, among other things, ajax modal popup extender:
<ajax:modalpopupextender id="mpe" runat="server" targetcontrolid="btnchangepassword" popupcontrolid="pnlpasswordchanging" backgroundcssclass="modalbackground" dropshadow="true" cancelcontrolid="btncancel" oncancelscript="ulc_changepw_cancelbtnclick();" />
nothing special here. problem comes backgroundcssclass
attribute—it requires css class called modalbackground. unfortunately cannot add css class user control in way survives postbacks.
if add modalbackground class .ascx page:
<style type="text/css"> .modalbackground { background-color: #a1a1a1; filter: alpha(opacity=70); opacity: 0.7px; } </style>
...it show property when first loaded, not after subsequent postbacks. of course define modalbackground within page itself, or within seperate, standalone css file called user control, neither solution work me.
is there no way create css class programmatically , add page? i'm looking css equivilant javascript's registerclientscriptblock
function:
dim controlnamescript = string.format("<script type='text/javascript'> var appmenuname = '{0}' </script>", me.clientid) me.page.clientscript.registerclientscriptblock(mytype, "controlname", controlnamescript)
thanks!
if css defined in .ascx file, should rendered every time, postback or not. unless control set visible="false".
one workaround define css code within asp:literal block on control. control can expose public function returns contents of literal caller. if host going make control invisible, can grab css code using public function, , place within head section of page. in way, css definition should there, regardless of visibility setting of control.
in larger scheme of things, adam correct: it's better keep css code in .css files wherever possible.
Comments
Post a Comment