Wednesday, March 18, 2009

Escape From <asp:image> Default CSS

How to get rid of ASP.NET default styling for asp:image??? Ppl says it is a [bug]... donno...
BTW, here is the workaround:

1. Create 2 classes

Public Class BorderlessImage
Inherits System.Web.UI.WebControls.Image
Public Overrides Property BorderWidth() As System.Web.UI.WebControls.Unit
Get
If MyBase.BorderWidth.IsEmpty Then
Return Unit.Pixel(0)
Else
Return MyBase.BorderWidth
End If
End Get
Set(ByVal value As System.Web.UI.WebControls.Unit)
MyBase.BorderWidth = value
End Set
End Property
End Class

Public Class BorderlessImageButton
Inherits System.Web.UI.WebControls.ImageButton
Public Overrides Property BorderWidth() As System.Web.UI.WebControls.Unit
Get
If MyBase.BorderWidth.IsEmpty Then
Return Unit.Pixel(0)
Else
Return MyBase.BorderWidth
End If
End Get
Set(ByVal value As System.Web.UI.WebControls.Unit)
MyBase.BorderWidth = value
End Set
End Property

2. Add into web.config

<system.web>
<pages>
<tagmapping>
<add mappedtagtype="BorderlessImage" tagtype="System.Web.UI.WebControls.Image">
<add mappedtagtype="BorderlessImageButton" tagtype="System.Web.UI.WebControls.ImageButton">
</pages>
</SYSTEM.WEB>

That's it. Done! Enjoy...

No comments:

Post a Comment