2
Reply

change alt text on image and link href

andrew slaughter

andrew slaughter

Oct 15 2010 6:32 AM
2.8k
Hi all

I'm in the process of writing a site for multi languages so all the content, href links and alt text for the images is stored in a db in the format 
contentid        countrycode         pagecontent         contenttype

all this data is info is then stored in a dataset which is looped through for each page using the code below. however I think I need to case the a href id into something but have no idea what and because the <img doesnt have a closing </img it cant find it. 

for the images i did think about changing the <img tags to <asp:Image tags if this would help 

foreach (DataRow theRow in ds.Tables[0].Rows)
{
string control = theRow["ContentId"].ToString();
HtmlContainerControl ctrl = FindControlRecursive(this, control) as HtmlContainerControl;
if (ctrl != null)
{
   //Response.Write(theRow["ContentType"].ToString());
   //control.inn
   //Object objControl = (Object)control;
   //string control = "homeText";
   //HtmlContainerControl
   //HtmlContainerControl ctrl = FindControlRecursive(this, control) as HtmlContainerControl;
   if (theRow["ContentType"].ToString() == "text")
   {
ctrl.InnerHtml = theRow["PageContent"].ToString();
   }
   if (theRow["ContentType"].ToString() == "link")
   {
//ctrl.HRef = theRow["PageContent"].ToString();
//ctrl.NavigateUrl = theRow["PageContent"].ToString();
//neither work
   }
   if (theRow["ContentType"].ToString() == "alt")
   {
//never finds the control 
//i believe its because and image tag isnt a proper htmlcontainercontrol
//because it has not </img>
   }
}
}

private Control FindControlRecursive(Control Root, string Id)        
{            
    //if current control is the one to be searched for then return it            
    if (Root.ID == Id)                 
return Root;             
    //if not, call search on each sub control            
    foreach (Control Ctl in Root.Controls)            
    {                
Control FoundCtl = FindControlRecursive(Ctl, Id);                 
//Bubble the located control back up to original call if it is found                
if (FoundCtl != null)                     
   return FoundCtl;             
    }             
    //if nothing is found and no sub controls remain then return null for this branch            
    return null;         
}

thanks for any help or pointers 

Answers (2)
Next Recommended Forum