开发者

How to get all img html on RenderChildren event

I'd like to know if it's possible to get a reference to all img controls on a page though the renderchildren method. 开发者_StackOverflowBasically, 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;
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜