Solved

Calling a custom html tag in codebehind

Posted on 2011-02-16
6
493 Views
Last Modified: 2012-05-11
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("PictureThumb") %>' longdesc='<%# "/" + Application("SysUserDir") + Container.DataItem("Picture") %>' onclick="enlarge(this);" class="Enlargeit_thumbnail" />


So I need to call that property in the codebehind, in the databound

like so
 CType(cell.FindControl("ImageZoomPort"), 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


0
Comment
Question by:TheWebGuy38
  • 2
  • 2
6 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 34913559
Never worked with jquery. Can't u use .src instead of longdesc? Wht exactly does longdesc do?
0
 
LVL 10

Expert Comment

by:P1ST0LPETE
ID: 34913596
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:
 
<%@ 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>

Open in new window


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());
    }
}

Open in new window

0
 

Author Comment

by:TheWebGuy38
ID: 34913601
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("longdesc") "


 CType(cell.FindControl("ImageZoomPort"), System.Web.UI.HtmlControls.HtmlImage).Attributes.Item("longdesc") = "/" + Application("SysUserDir") + Picture


seems to work!
0
 
LVL 10

Accepted Solution

by:
P1ST0LPETE earned 500 total points
ID: 34913620
Actually, forgive me for posting more than what you need :-)

After you put the runat="server" attribute on the <img> you can access the "longdesc" attribute like this:

string longdesc = ImageZoomPort.Attributes["longdesc"].ToString();
0
 

Author Comment

by:TheWebGuy38
ID: 34913636
this is good to know. I'm sure this will come in handy a lot :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Object Oriented Programming, C#, referencing, scoping. 13 69
Linq asp.net mvc 13 17
Limit the # times a macro code will run 14 50
Easy filter aspnet 2 24
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question