Solved

Calling a custom html tag in codebehind

Posted on 2011-02-16
6
497 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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