Add attribute to a dynamically created imagebutton control
-
for loop { ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'"); } Hello, I have an imagebutton instance dynamically generated. The code works fine except the mouse over effect on the button becomes a big red X everytime my mouse hovers over the image. Does this have something to do with the dynamic generation of my imageButton? On the contrary, if I have an imagebutton available in markup with similar attribute, everything works fine. Please help. Thank you.
Gerri
-
for loop { ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'"); } Hello, I have an imagebutton instance dynamically generated. The code works fine except the mouse over effect on the button becomes a big red X everytime my mouse hovers over the image. Does this have something to do with the dynamic generation of my imageButton? On the contrary, if I have an imagebutton available in markup with similar attribute, everything works fine. Please help. Thank you.
Gerri
try doing a "View source" on the generated page to see what is actually sent down to the browser, and how it differs from the markup code that works I'm not quite sure about your for...loop ? However you're looping, you can't create more than one control with the same ID... Fred
-
try doing a "View source" on the generated page to see what is actually sent down to the browser, and how it differs from the markup code that works I'm not quite sure about your for...loop ? However you're looping, you can't create more than one control with the same ID... Fred
-
for loop { ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'"); } Hello, I have an imagebutton instance dynamically generated. The code works fine except the mouse over effect on the button becomes a big red X everytime my mouse hovers over the image. Does this have something to do with the dynamic generation of my imageButton? On the contrary, if I have an imagebutton available in markup with similar attribute, everything works fine. Please help. Thank you.
Gerri
CandyMe wrote:
ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'");
ImageButton accepts 'ImageUrl' attribute rather than 'Src' attribute which is an attribute for HTML Image. Try modifying your last line of code to--- img.Attributes.Add("onmouseover", "this.ImageUrl='" + imgMouseOverURL + "'"); Hope this works :)
-
CandyMe wrote:
ImageButton img = new ImageButton(); img.ImageUrl = "a.gif"; img.Attributes.Add("onmouseover", "this.src='" + imgMouseOverURL + "'");
ImageButton accepts 'ImageUrl' attribute rather than 'Src' attribute which is an attribute for HTML Image. Try modifying your last line of code to--- img.Attributes.Add("onmouseover", "this.ImageUrl='" + imgMouseOverURL + "'"); Hope this works :)
No, that's not right. The Attribute that that line adds is to the control as it is rendered client-side, and therefore you must use the client-side properties. The original code is right, in that respect.
-
No, that's not right. The Attribute that that line adds is to the control as it is rendered client-side, and therefore you must use the client-side properties. The original code is right, in that respect.