Control Adapter for the Image control

I apologise if this is not the right group to ask, but I didn't see a better one...

I'm trying to write a Control Adapter to override the rendering of the asp:Image control, mainly because I have some very image-heavy pages and I don't want the obligatory style="boder-width:0px;" that ASP.NET annoyingly applies to every image, thus adding to the overall page weight.

This is what I'm trying to...

public class ImageAdapter : WebControlAdapter
{
protected override void Render(HtmlTextWriter writer)
{
Image imageControl;
imageControl = this.Control as Image;
if (imageControl != null)
{
if (imageControl.GetType().Equals(typeof(System.Web.UI.WebControls.Image)))
{
if (!String.IsNullOrEmpty(imageControl.ImageUrl))
{
writer.WriteBeginTag("img");
writer.WriteAttribute("id", imageControl.ClientID);
writer.WriteAttribute("src", imageControl.ResolveUrl(imageControl.ImageUrl));
if (!String.IsNullOrEmpty(imageControl.AlternateText))
writer.WriteAttribute("alt", imageControl.AlternateText);
if (imageControl.GenerateEmptyAlternateText)
writer.WriteAttribute("alt", string.Empty);
if (!String.IsNullOrEmpty(imageControl.CssClass))
writer.WriteAttribute("class", imageControl.CssClass);

writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}
}
}
else
base.Render(writer);
}
}
}

... but I'm not sure it this is how it should be done. I mean...it works -- but is there a more elegant way of writing this control adapter?

Any thoughts or feedback would be appreciated. 

0
KevinTurner71
6/5/2008 3:57:47 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

2 Replies
828 Views

Similar Articles

[PageSpeed] 40

hi kevin,

i searched it for you, and i find somethink link below,

http://forums.asp.net/p/1058023/1511234.aspx

i hope this helps you..


ihsany
######
Make It Easy
--------------dont forget to click <Mark As Answer>------------------
0
ihsany
6/5/2008 8:57:20 AM

 Ah, excellent -- thank you! Once again the solution was already posted in the forum!

 

0
KevinTurner71
6/5/2008 10:55:13 AM
Reply:

Similar Artilces:

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

How do I use an embedded resource image in an imagebutton control in a custom server control?
I have a custom server control that I am building that includes an imagebutton control. I want to be able to use an image that I have included in the control as an embedded resource. Am I missing something here.... How do I get the imagecontrol to use the embedded resource image instead of the imageurl? Note : I'm still on 1. - not 2. yet....I build the the image control as follows.... Dim imgButton As New ImageButtonimgButton.ToolTip = Me.ToolTipimgButton.ImageUrl = ?????????AddHandler imgButton.Click, AddressOf imgButton_ClickControls.Add(imgButton)thanks I had the same question. Found ...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Control Adapter Overriding Server Control
I made a custom server control and a control adapter is overriding that. I would like to use both, so how can I stop it from overriding the customer server control, but still render what I need for asp.net controls? Michael S. Flynn...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

BUG: Image Controls in UpdateProgess Control: Can not use FindControl() methods to get Image
There is a single UpdateProgress control on the page. as such: <ajax:UpdateProgress  ID="UpdateProgress1" runat="server"   DisplayAfter="100" >         <ProgressTemplate>                <div style="border:2px solid #0099FF; background-color:#EFEFEF; padding:10px; width:200px; height:20px;">               Updating Panel            </div&...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

Server Controls Within Server Controls
I'm a little new to server controls so this question may seem silly, but has anyone had trouble with events from custom server controls that are embedded in other custom server controls? I'm trying to create a composite control that creates a list of items and creates an instance of another composite control for each item. So for example the list could be a collection of addresses that has an editor composite control for each item. The editor composite control allows the user to edit the item and click on a save button. This works fine if it is on it's own (ie not part of the list ...

Web resources about - Control Adapter for the Image control - asp.net.custom-server-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Now you can control your GoPro Camera from Apple Watch
One of the nicest features of the GoPro camera is the ability to control it using the iPhone app. With the GoPro App , you can easily control ...

Microsoft Band updated to include music controls and inactivity alerts
... Microsoft Band came out, the company is adding functionality with a small software update. The two biggest features of this update—music controls ...

Control a car's features with a glance? Not science fiction
Filed under: Emerging Technologies , Infotainment , Technology Press a button to change your car's climate controls? Turn a knob to view your ...

"... Trump owns and controls the media... they can't not cover him... his audience is bigger than theirs ...
... their army (i.e., the media) can't take out their enemy. They don't have the slightest idea what to do.... The media, in their own minds, controls ...

How to control your iPhone by just tilting your head
... the best sight, hearing, or motor functions to still use iOS to its fullest capabilities — but they can also be used to customize your controls. ...

Fox Presents Ben Stein As An Awesome, Stupendous Gun Control Genius
Fox News host Neil Cavuto was super-impressed with “great writer and thinker” Ben Stein's opposition to gun control. “The problem is not gun ...

White House: We’re Not Going To Wait Until Something Happens To Pass Gun Control
Reporter: 'Where any of the recent mass shooters on the no-fly list?' Earnest: 'Not that I'm aware of'

The NFL Should Seize Control Of The Cleveland Browns
Drew Magary’s Thursday Afternoon NFL Dick Joke Jamboroo runs every Thursday during the NFL season. Email Drew here . Read more...

Halo 5 is getting advanced control options
... is a good day. There's more to next week's update for Halo 5: Guardians than Forge mode, maps, and REQs. The game is also expanding its control ...

Resources last updated: 12/13/2015 11:17:20 AM