TheWebGuy38
asked on
Calling a custom html tag in codebehind
OK, here is my problem. I'm using a custom jquary app which works great, but it adds a custom html tage.
eg. "longdesc"
<img id="ImageZoomPort" src='<%# "/" + Application("SysUserDir") + Container.DataItem("Pictur eThumb") %>' longdesc='<%# "/" + Application("SysUserDir") + Container.DataItem("Pictur e") %>' onclick="enlarge(this);" class="Enlargeit_thumbnail " />
So I need to call that property in the codebehind, in the databound
like so
CType(cell.FindControl("Im ageZoomPor t"), System.Web.UI.HtmlControls .HtmlImage ).longdesc = "/Images/NoPhotoLarge.jpg"
but obviosly, that can't be done. because the tag is a custom tag.
Am hoping someone has a workaround for this problem
any help would be greatly appreciateed
eg. "longdesc"
<img id="ImageZoomPort" src='<%# "/" + Application("SysUserDir") + Container.DataItem("Pictur
So I need to call that property in the codebehind, in the databound
like so
CType(cell.FindControl("Im
but obviosly, that can't be done. because the tag is a custom tag.
Am hoping someone has a workaround for this problem
any help would be greatly appreciateed
Never worked with jquery. Can't u use .src instead of longdesc? Wht exactly does longdesc do?
To access the control on the server you must add the runat="server" attribute to the <img>. Other than that it shouldn't be too hard. Have a look at the example below:
Markup:
Code Behind:
Markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<img id="ImageZoomPort" runat="server" src="source" longdesc="/Images/NoPhotoLarge.jpg" onclick="enlarge(this)" class="Enlargeit_thumbnail" />
</div>
</form>
</body>
</html>
Code Behind:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Collections;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
IEnumerator keys = ImageZoomPort.Attributes.Keys.GetEnumerator();
StringBuilder message = new StringBuilder();
while (keys.MoveNext())
{
string key = keys.Current.ToString();
message.Append(key + ": " + ImageZoomPort.Attributes[key] + "<br />");
}
Response.Write(message.ToString());
}
}
ASKER
Oh wait! I just figured it out. have no clue how I figured it out. but here's what I did in the codebehind
".Attributes.Item("longdes c") "
CType(cell.FindControl("Im ageZoomPor t"), System.Web.UI.HtmlControls .HtmlImage ).Attribut es.Item("l ongdesc") = "/" + Application("SysUserDir") + Picture
seems to work!
".Attributes.Item("longdes
CType(cell.FindControl("Im
seems to work!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this is good to know. I'm sure this will come in handy a lot :)