Monday, March 26, 2012

Server tage not well formed

Hello,
Can anyone tell me if this is possible. If yes then can you identify the error in this line. I am writing this line of code in .aspx file in VB.NET v1.1

<asp:Image id="productImage" runat="server" ImageUrl="<%# ConfigurationSettings.AppSettings("virtualdir") & DataBinder.Eval(Container.DataItem,"WebImageName")%>"></asp:Image>

The error says server tag not well formed.

Thanks

I would create a variable (string), to concatenate this:
ConfigurationSettings.AppSettings("virtualdir") & DataBinder.Eval(Container.DataItem,"WebImageName")

Dim sPath as string
sPath=ConfigurationSettings.AppSettings("virtualdir") & WebImageName ' (substitute WebImageName with however you retrieve this-like datareader/dataset...

Then, in your ImageURL:
ImageURL='<%# sPath %>'


Thanks for the help... But how can i write a fuction in the server tag. Do i need to write it seperately and make be call that function, if so can u say how can i do that.

Thanks Again.


It is a better idea if you use a method in the code behind to use the concatenation.

protected string FormatPath(string webImageName)
{
string virtualDirectory = (string) ConfigurationSettings.AppSettings["virtualdir"];
return virtualDirectory + webImageName;
}

Hope this helps!
I forgot you need to add something like this also:

<asp:Image id="productImage" runat="server" ImageUrl='<%# (string) FormatPath(DataBinder.Eval("Container.DataItem","webImageUrl") %>' "></asp:Image

0 comments:

Post a Comment