在锚标记中使用服务器标记

时间:2022-11-19 14:48:46

I would like to use a property ID value in the anchor tag as below:

我想在锚标记中使用属性ID值,如下所示:

<a id="aExample" href="/test/example.aspx?id=<%# Id %>" runat="server">Example</a>

But when the page is rendered instead of getting the href as "/test/example.aspx?id=5" i am getting "/test/example.aspx?id=<%# Id %>" as plain text assigned as href of the anchor.

但是当呈现页面而不是将href作为“/test/example.aspx?id=5”时,我得到“/test/example.aspx?id=<%# Id%>”作为指定为href的纯文本锚。

Id = is a property defined in code behind.

Id =是在后面的代码中定义的属性。

Can anybody help me whats wrong with this? N.B: I need runat="server"` to be present.

任何人都可以帮我解决这个问题吗? N.B:我需要runat =“server”`才能出现。

My tag is not inside any Grid view control but within a user control. <%=

我的标记不在任何网格视图控件内,而是在用户控件中。 <(%)=

6 个解决方案

#1


0  

Please try this,

请试试这个,

<a id="aExample" href='<%# string.Format("/test/example.aspx?id={0}", Id) %>'  runat="server">Example</a>

#2


1  

Try this,

尝试这个,

if you want get variable value from your .cs so you can use. Declare variable in your page. .cs page

如果你想从你的.cs获得变量值,那么你可以使用。在页面中声明变量。 .cs页面

 public int Id = 0;

aspx page

aspx页面

<a id="aExample" href="/test/example.aspx?id=<%= Id %>" runat="server">Example</a>

and your a tag is inside in gridview control so you can use like...

并且您的标签位于gridview控件内部,因此您可以使用...

<a id="aExample" href="/test/example.aspx?id=<%#Eval("Id")%>" runat="server">Example</a>

#3


0  

Maybe you can try this

也许你可以试试这个

<asp:HyperLink ID="aExample" runat="server" NavigateUrl='<%# String.Format("/test/example.aspx?id={0}", Eval("Id")) %>'>Example</asp:HyperLink>

#4


0  

You can do this in code behind (if its not inside Gridview or some other control like that)

您可以在后面的代码中执行此操作(如果它不在Gridview内或其他类似的控件中)

aExample.Href = "/test/example.aspx?id="+ YourEntity.Id;

#5


0  

Try this

尝试这个

<a id="aExample" href='<%= CompleteURL %>' runat="server">Example</a>

If you can build and bind the complete URL in your property (code behind). I think this can be optimal solution. This way you can also change your URL dynamically.

如果您可以在您的属性中构建和绑定完整的URL(代码隐藏)。我认为这可以是最佳解决方案。这样,您还可以动态更改URL。

#6


0  

You can also set the href of anchor tag in CodeBehind.

您还可以在CodeBehind中设置锚标记的href。

CodeBehind:

代码隐藏:

int Id = 4;
aExample.HRef = "/test/example.aspx?id=" + Id;

Thanks

谢谢

#1


0  

Please try this,

请试试这个,

<a id="aExample" href='<%# string.Format("/test/example.aspx?id={0}", Id) %>'  runat="server">Example</a>

#2


1  

Try this,

尝试这个,

if you want get variable value from your .cs so you can use. Declare variable in your page. .cs page

如果你想从你的.cs获得变量值,那么你可以使用。在页面中声明变量。 .cs页面

 public int Id = 0;

aspx page

aspx页面

<a id="aExample" href="/test/example.aspx?id=<%= Id %>" runat="server">Example</a>

and your a tag is inside in gridview control so you can use like...

并且您的标签位于gridview控件内部,因此您可以使用...

<a id="aExample" href="/test/example.aspx?id=<%#Eval("Id")%>" runat="server">Example</a>

#3


0  

Maybe you can try this

也许你可以试试这个

<asp:HyperLink ID="aExample" runat="server" NavigateUrl='<%# String.Format("/test/example.aspx?id={0}", Eval("Id")) %>'>Example</asp:HyperLink>

#4


0  

You can do this in code behind (if its not inside Gridview or some other control like that)

您可以在后面的代码中执行此操作(如果它不在Gridview内或其他类似的控件中)

aExample.Href = "/test/example.aspx?id="+ YourEntity.Id;

#5


0  

Try this

尝试这个

<a id="aExample" href='<%= CompleteURL %>' runat="server">Example</a>

If you can build and bind the complete URL in your property (code behind). I think this can be optimal solution. This way you can also change your URL dynamically.

如果您可以在您的属性中构建和绑定完整的URL(代码隐藏)。我认为这可以是最佳解决方案。这样,您还可以动态更改URL。

#6


0  

You can also set the href of anchor tag in CodeBehind.

您还可以在CodeBehind中设置锚标记的href。

CodeBehind:

代码隐藏:

int Id = 4;
aExample.HRef = "/test/example.aspx?id=" + Id;

Thanks

谢谢