We help IT Professionals succeed at work.

Simple concatination that I do not know why it is not working.

Hi,

I need to concat the value of <%$LocalizationService:ReadMore%> and <%#Eval("Title")%>, separating it with "-" then place it in the title of an anchor tag. I have the below code but this does not work. Any ideas why?
<a class="whitearrow-link" title='<%$LocalizationService:ReadMore%> - <%#Eval("Title")%>' rel='products_featured:readmore' name='<%#Eval("PageGUID")%>' href='<%#HttpUtility.HtmlEncode(Eval("Url"))%>'><asp:Literal runat="server" ID="readMore" Text ="<%$LocalizationService:ReadMore%>"></asp:Literal></a>

Open in new window

Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2014

Commented:
Do you get anything? Or nothing? Or just "-"?

Also try

'<%# String.Format("{0} - {1}", LocalizationService:ReadMore, Eval("Title")) %>'
Well... the concatenation you're using should be fine, so I think the problem is with the values returned by your expressions, probably they are wrong or returning something different from what you expect.

This is all we can tell you with the info you provide us.
Commented:
AFAIK, <%$ expressionPrefix: expressionValue %> reads information from Web.config file (see http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx).

expressionPrefix could be one of these values; AppSettings, ConnectionStrings, or Resources
expressionValue is name of XML tag you want its value

For example, you added following setting in Web.config

<appSettings>
  <add key="copyright" value="(c)Copyright 2004 Northwind Traders"/>
</appSettings>

so you can display it on page by

<%$ AppSettings: copyright %>

My question is what are LocalizationService and ReadMore?

Author

Commented:
CodeCruiser,

It gives me an error.

gnoon,

LocalizationSrvice is a class while readmore is the key in the localization.

Author

Commented:
CodeCruiser,

>> Do you get anything? Or nothing? Or just "-"?

I get an error. Attached is the error.

gnoon,

LocalizationSrvice is a class while readmore is the key in the localization.
error.png
Wow... do EE charge you on a word basis?

Cannot you at least, specify WHAT ERROR are you receiving with CodeCruiser option?

Are you aware of how difficult is for us to guess what is happening when you give so few info on your questions and comments?

Please, help us to help you...

Now... if LocalizationService is a class, and readmore one of it's attributes have you tried to extract if through: <%= LocalizationService.readmore %>  ?

Author

Commented:
Hi BardoBrave,

I attached the image of the error I received. My Apology for not being specific.

Author

Commented:
Below code works:

title='<%#Eval("Title")%>'
title='<%$LocalizationService:ReadMore%>'

but when I tried to concatenate both <%$LocalizationService:ReadMore%> and <%#Eval("Title")%>. It does not work.

Tried something like this

title="<%# LocalizationService:ReadMore + " - " + Eval("Title")%>"
and this
title="<%$LocalizationService:ReadMore%><%#" - " + Eval("Title")%>"
and this
title="<%$LocalizationService:ReadMore%>+ - +<%#Eval("Title")%>"
all fails.

This is the error I received when I tried the code suggested by codecruiser.

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'LocalizationService' is not declared.

Author

Commented:
Bardobrave,

>>if LocalizationService is a class, and readmore one of it's attributes have you tried to extract if through: <%= LocalizationService.readmore %>

The value is not extract instead the tooltip displays as "<%= LocalizationService.readmore %>".

Anymore ideas?
Lets see...

Have you tried this?

title='<%$LocalizationService:ReadMore%>' - '<%# Eval("Title")%>'
And this?

title='<%$LocalizationService:ReadMore%>' + ' - ' + '<%#Eval("Title")%>'

Author

Commented:
Hi,

The first suggestion is an error. Below is the error I received.
Timestamp: 12/7/2011 12:42:33 PM
Message: <Exception handlingInstanceId="c59013fc-5b04-4591-a321-181b8918ae95">
  <Description>An exception of type 'System.Web.HttpException' occurred and was caught.</Description>
  <DateTime>2011-12-07 20:42:33Z</DateTime>
  <ExceptionType>System.Web.HttpException, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</ExceptionType>
  <Message>Literal expressions like '&lt;%$LocalizationService:ReadMore%&gt;' are not allowed. Use &lt;asp:Literal runat="server" Text="&lt;%$LocalizationService:ReadMore%&gt;" /&gt; instead.</Message>
  <Source>System.Web</Source>
  <HelpLink />
  <Property name="ErrorCode">-2147467259</Property>
  <Property name="Data">System.Collections.ListDictionaryInternal</Property>
  <Property name="TargetSite">Void ProcessError(System.String)</Property>
  <StackTrace>   at System.Web.UI.TemplateParser.ProcessError(String message)
   at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)
   at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)</StackTrace>
  <additionalInfo>
    <info name="MachineName" value="MOJODEV" />
    <info name="TimeStamp" value="12/7/2011 12:42:33 PM" />
    <info name="FullName" value="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <info name="AppDomainName" value="/LM/W3SVC/584322660/Root-2-129677342978005552" />
    <info name="ThreadIdentity" value="DEVELOPMENT\Administrator" />
    <info name="WindowsIdentity" value="DEVELOPMENT\Administrator" />
  </additionalInfo>
</Exception>
Category: Error Log
Priority: 0
EventId: 100
Severity: Error
Title:MOBAR Client Exception Handling 
Machine: MOJODEV
Application Domain: /LM/W3SVC/584322660/Root-2-129677342978005552
Process Id: 3680
Process Name: c:\windows\system32\inetsrv\w3wp.exe
Win32 Thread Id: 3300
Thread Name: 
Extended Properties: 

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Open in new window

Author

Commented:
And for the second suggestion, I also receive an error.

Any more ideas?
Event Type:	Warning
Event Source:	ASP.NET 2.0.50727.0
Event Category:	Web Event 
Event ID:	1310
Date:		12/7/2011
Time:		8:44:24 PM
User:		N/A
Computer:	MOJODEV
Description:
Event code: 3006 
Event message: A parser error has occurred. 
Event time: 12/7/2011 8:44:24 PM 
Event time (UTC): 12/7/2011 12:44:24 PM 
Event ID: 928321e704bd40b5b55f2833b70532c2 
Event sequence: 270 
Event occurrence: 3 
Event detail code: 0 
 
Application information: 
    Application domain: /LM/W3SVC/584322660/Root-2-129677342978005552 
    Trust level: WSS_Minimal 
    Application Virtual Path: / 
    Application Path: C:\Inetpub\wwwroot\wss\VirtualDirectories\11130\ 
    Machine name: MOJODEV 
 
Process information: 
    Process ID: 3680 
    Process name: w3wp.exe 
    Account name: DEVELOPMENT\Administrator 
 
Exception information: 
    Exception type: HttpParseException 
    Exception message: Literal expressions like '<%$LocalizationService:ReadMore%>' are not allowed. Use <asp:Literal runat="server" Text="<%$LocalizationService:ReadMore%>" /> instead. 
 
Request information: 
    Request URL: http://mojodev:11130/us-en/Pages/SectionTopic.aspx 
    Request path: /us-en/Pages/SectionTopic.aspx 
    User host address: 10.205.86.49 
    User: DEVELOPMENT\Administrator 
    Is authenticated: True 
    Authentication Type: Negotiate 
    Thread account name: DEVELOPMENT\Administrator 
 
Thread information: 
    Thread ID: 21 
    Thread account name: DEVELOPMENT\Administrator 
    Is impersonating: True 
    Stack trace:    at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
   at System.Web.UI.TemplateParser.ParseReader(StreamReader reader, VirtualPath virtualPath)
   at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath)
   at System.Web.UI.TemplateParser.ParseInternal()
   at System.Web.UI.TemplateParser.Parse()
   at System.Web.UI.TemplateParser.Parse(ICollection referencedAssemblies, VirtualPath virtualPath)
   at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()
   at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)
   at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
   at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
   at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath)
   at System.Web.UI.TemplateControl.LoadControl(String virtualPath)
   at CIO.MarCom.WebParts.SectionTopicWebpart.CreateLiveMode()
   at CIO.MarCom.WebParts.SectionTopicPresenter.OnViewLoad_Handler()
   at CIO.MarCom.WebParts.ISectionTopicView.ViewLoadEventHandler.Invoke()
   at CIO.MarCom.WebParts.SectionTopicWebpart.CreateChildControls()
   at System.Web.UI.Control.EnsureChildControls()
   at System.Web.UI.WebControls.WebParts.Part.get_Controls()
   at Accenture.MOBAR.Common.Web.UI.MOBARWebPart.OnInit(EventArgs e)
   at CIO.MarCom.WebParts.SectionTopicWebpart.OnInit(EventArgs e)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Control.AddedControl(Control control, Int32 index)
   at System.Web.UI.ControlCollection.Add(Control child)
   at System.Web.UI.WebControls.WebParts.WebPartManager.WebPartManagerControlCollection.AddWebPartHelper(WebPart webPart)
   at System.Web.UI.WebControls.WebParts.WebPartManager.WebPartManagerControlCollection.AddWebPart(WebPart webPart)
   at System.Web.UI.WebControls.WebParts.WebPartManager.AddWebPart(WebPart webPart)
   at System.Web.UI.WebControls.WebParts.WebPartManagerInternals.AddWebPart(WebPart webPart)
   at Microsoft.SharePoint.WebPartPages.SPWebPartManager.AddWebPartWithRetry(WebPart webPart)
   at Microsoft.SharePoint.WebPartPages.SPWebPartManager.AddDynamicWebPart(WebPart webPart)
   at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CreateWebPartsFromRowSetData(Boolean onlyInitializeClosedWebParts)
   at Microsoft.SharePoint.WebPartPages.SPWebPartManager.LoadWebParts()
   at Microsoft.SharePoint.WebPartPages.SPWebPartManager.OnPageInitComplete(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Web.UI.Page.OnInitComplete(EventArgs e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.SECTIONTOPICPAGE_ASPX_932100003.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ed5a49f2\464fbe2\App_Web_sectiontopicpage.aspx_932100003.vpmcop_w.0.cs:line 0
   at Microsoft.SharePoint.Publishing.TemplateRedirectionPage.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
 
 
Custom event details: 

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Open in new window

So this:

title='<%#Eval("Title")%>'
title='<%$LocalizationService:ReadMore%>'

works, but:

title='<%$LocalizationService:ReadMore%> - <%# Eval("Title")%>'

returns an error?

That's weird.

Have you tried to assign both values to variables and concatenate those variables?

Most Valuable Expert 2012
Top Expert 2014

Commented:
Did you try my string.format example? May be you can call a function which would return the value

'<%# String.Format("{0} - {1}", GetMyString(), Eval("Title")) %>'

Author

Commented:
Bardobrave,

>> Have you tried to assign both values to variables and concatenate those variables?

I do not have an idea how to do what you suggests.

Codecruiser,

>>Did you try my string.format example?

Yes, I did. It returns an error. Below is the error description I got.

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'LocalizationService' is not declared



Author

Commented:
Hi to all,

Additional info:

The LocalizationService is a custom dollar expression, which retrieves values from a list where the localization of text is stored in Moss 2007.

I think the problem is ASP.Net does not allow to concatenate dollar expression with data binding expression.
Commented:
Yep, it's not allowed due to limitation of evaluation period in life cycle. You need to choose one expression for the anchor control.

Fact:
<%$ %> and <%# %> evaluate value from different datasources (one from MOSS, the other from SQL).
<%$ %> is done before databinding in <%# %>, no way to get binding value within <%$ %> for concat (I mean in your custom class).

Two solutions I can thought
1. open a new connection within pound expression to MOSS to get localize info for concat, but complex logic is needed to reduce opening connections.

<a title='<%# GetConcatString(Eval('Title'), ???) %>' ...

2. (Recommended) using

<a id='readmore' runat='server' title='<%$LocalizationService:ReadMore%>' ...

then in code behind append the text ' - ' + Eval('Title') to the title during binding process

protected void Repeater1_DataBound(object source, RepeaterItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.AlternatingItem ||
      e.Item.ItemType == ListItemType.Item)
  {
    HtmlAnchor anc = (HtmlAnchor)e.Item.FindControl("readmore");
    if (anc != null)
      anc.Attributes["title"] += " - " + DataBinder.Eval(e.Item.DataItem, "Title");
  }
}

Open in new window

P.S. I'm using Repeater control in the sample. You must change it to match your data view control.

Cheers