Solved

Calling a custom html tag in codebehind

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now