?
Solved

Calling a custom html tag in codebehind

Posted on 2011-02-16
6
Medium Priority
?
502 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 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