服务器标记未在asp

服务器标记未在asp

本文介绍了服务器标记未在asp:Hyperlink中解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须承认,我是ASP.NET的新手,可耻的是尚未真正在客户端页面上使用服务器标签.我的页面上有一个中继器,该中继器可遍历数据表的行,并使用以下标记显示每个项目的超链接对象:

I have to admit to start that I am relatively new to ASP.NET and shamefully have not really used server tags on the client side page yet. I have a repeater on my page that iterates through the rows of a datatable and shows a hyperlink object for each item using the below tag:

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/DiseaseInfo/Syndrome.aspx?SyndromeID=<%# Eval('SYNDROME_ID')%>&SpeciesID=<%# Eval('SPECIES_ID')%>" Text='<%# Eval("SYNDROME_NAME").ToString%>'></asp:HyperLink>

我遇到的问题是服务器没有呈现出<%#%>标签.如果我将相同的链接放入标签,则可以正常工作.我确信这与超链接已经在服务器端呈现的事实有关,但是我无法弄清楚如何进行更改以使其正常工作.任何帮助将不胜感激.

The problem that I am having is that the server doesn't render out the <%# %> tags. If I put this same link into an tag then it works just fine. I am sure that it has to do with the fact that the hyperlink is already being rendered on the server-side, but I can't figure out how to change things to get it to work correctly. Any help would be greatly appreciated.

推荐答案

反转单/双引号的顺序.

Reverse the order of your single / double quotes.

<asp:HyperLink runat="server" NavigateUrl='~/DiseaseInfo/Syndrome.aspx?
  SyndromeID=<%# Eval("SYNDROME_ID")%>&SpeciesID=<%# Eval("SPECIES_ID")%>'
  Text='<%# Eval("SYNDROME_NAME").ToString()%>'>
</asp:HyperLink>

这通常在JavaScript/HTML级别上无关紧要,但是C#/VB的正确引号是双引号,应在Eval()方法中使用.

This normally doesn't matter at a JavaScript / HTML level but the correct quote for C# / VB is a double quote which should be used within the Eval() method.

一种更好的方法是调用一个方法来返回这个稍微复杂的网址:

A slightly better approach would be to invoke a method to return this somewhat complex url:

<asp:HyperLink runat="server" NavigateUrl='<%# GetUrl() %>' />

protected string GetUrl()
{
    return string.format("Syndrome.aspx?SyndromeID={0}...", Eval("SYNDROME_ID");
}

这篇关于服务器标记未在asp:Hyperlink中解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:27