Solved

Calling a custom html tag in codebehind

Posted on 2011-02-16
6
496 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

732 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