473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Adding attributes to webcontrols that generate nested elements

I'm trying to add an attribute to the hyperlink web control in asp.net. The hyperlink control renders to an img tag wrapped by an anchor tag. Calling hyperlink1.Attributes.Add('someKey','someValue') adds the attribute to the anchor tag and not the image tag. Any ideas on how to target the img tag's attributes?

Any help is appreciated
Thanks
Jun 5 '07 #1
2 1283
nateraaaa
663 Expert 512MB
Try using .FindControl("IDofImage") to access the image control. You can then create a new Image and assign the properties you wish to change to the new image. Try something like this.

Let's say your Image control is named imgOriginal on your page. Now create a new image that will reference imgOriginal.

Expand|Select|Wrap|Line Numbers
  1. System.Web.UI.WebControls.Image imgNew = (System.Web.UI.WebControls.Image)this.Page.FindControl("imgOriginal");
Now you can access the properites of the Image Control by using imgNew.

Expand|Select|Wrap|Line Numbers
  1. imgNew.ImageUrl = "Whatever you want";
Hope this helps

Nathan
Jun 5 '07 #2
Try using .FindControl("IDofImage") to access the image control. You can then create a new Image and assign the properties you wish to change to the new image. Try something like this.

Let's say your Image control is named imgOriginal on your page. Now create a new image that will reference imgOriginal.

Expand|Select|Wrap|Line Numbers
  1. System.Web.UI.WebControls.Image imgNew = (System.Web.UI.WebControls.Image)this.Page.FindControl("imgOriginal");
Now you can access the properites of the Image Control by using imgNew.

Expand|Select|Wrap|Line Numbers
  1. imgNew.ImageUrl = "Whatever you want";
Hope this helps

Nathan
The control I'm using is a hyperlink(System.Web.UI.WebControls.HyperLink). The hyperlink control renders an img element wrapped by an anchor element. The anchor element has an id attribute when rendered but the img element not. There is no image control on my webForm. The only thing FindControl will return is a reference to the hyperlink control. I am still looking for some way to add the attributes to the img tag from within the hyperlink object.
Thanks
Jun 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table...
12
by: Oberon | last post by:
I have a large HTML document. It has hundreds of <span>s which have no attributes so these <span>s are redundant. How can I remove these tags automatically? The document also has <span>s with...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
19
by: Sjaakie Helderhorst | last post by:
Hello, I need to add a Javascript event (onClick) to a servercontrol (asp:checkbox). Checkbox is named 'cbDoMail'. Assumed that 'cbDoMail.Attributes.Add("onClick", "doJavascriptThing()") would do...
0
by: I am Sam | last post by:
Ok whats wrong with my toolbar? When I debug I don't get an error message and the databinding is working correctly but the toolbar itself and the <iewc:ToolbarDropDownlist /> control isn't showing...
2
by: grawsha2000 | last post by:
Hello, How can I add a table to asp.net page dynamically with Code Behind style. I still can't find a way of doing it. This really causes me a big problem when I deal with records from...
2
by: Ken Fine | last post by:
In code, I'm adding javascript attributes to form elements on an ASP.NET page: body.Attributes.Add("onClick", "highlight(event);"); body.Attributes.Add("onKeyUp", "highlight(event);");...
6
by: Jakub.Bednarczuk | last post by:
Hallo everybody I have the problem with getting attributes values and also attributes names. I am reading an xml file with DOM. Lets see an example: file I read <root> <Def></Def>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.