tags:

views:

16

answers:

1

Hello, I'd like to know if it's possible to get a reference to all img controls on a page though the renderchildren method. Basically, I'm trying to seek the img tags to manually resolve their ~ path... This is the code I have so far...

override protected void RenderChildren(System.Web.UI.HtmlTextWriter writer)
{
    IterateControls(this);
    base.RenderChildren(writer);
}

private void IterateControls(Control objCTRL)
{
    if (objCTRL is LiteralControl)
        CheckForWildCard((LiteralControl)objCTRL);

    if (objCTRL.HasControls())
    {
        foreach(Control ctrl in objCTRL.Controls)
            IterateControls(ctrl);
    }
}

private void CheckForWildCard(LiteralControl objCtrl)
{
    // No img controls reach this point
    string sNewText = objCtrl.Text;
    sNewText = sNewText.Replace("~", Request.ApplicationPath);
    objCtrl.Text = sNewText;
}
A: 

Why don't you add runat="server" to all of your img tags so you don't have to bother doing this?

TheGeekYouNeed
Because that then changes the ids of the img tags, and that affects the jquery expressions on the page...
You can circumvent that by adding a css class to the image tag and have jQuery select elements via their class ('img.myClass') instead of their id ('#imgID1')
TheGeekYouNeed