如何在RenderChildren事件上获取所有img html

时间:2010-10-04 15:50:11

标签: asp.net image

我想知道是否可以通过renderchildren方法获取对页面上所有img控件的引用。基本上,我正在尝试寻找img标签来手动解决他们的〜路径...这是我到目前为止的代码......

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;
}

1 个答案:

答案 0 :(得分:0)

为什么不在所有img标签中添加runat =“server”,这样你就不必费心了?