在href<%= xx%>中使用服务器变量使用runat = server [英] using server variables in a href <%= xx %> with runat=server

查看:97
本文介绍了在href<%= xx%>中使用服务器变量使用runat = server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在aspx页面上使用如下所示的定位标记时,

When I use an anchor tag on an aspx page as below,

<a href="~/pages/page.aspx?id=<%= ServervariableName %>"> test </a>

它将获得正确分配给id的变量值,但不会正确路由页面,因为〜如果没有'a'标签上的runat ="server"属性,将无法评估〜.但是一旦添加了runat服务器属性,它就不再评估servervariable名称.是否有人知道这是如何工作的,或者我应该怎么做才能解决这两个问题?

it will get the variable value correctly assigned to id but it won't route the page correctly as the ~ will not be evaluated without the runat="server" attribute on the 'a' tag. But once I add the runat server attribute, it does not evaluate the servervariable name anymore.. Does anyone know how this works or what I should do to take care of both?

推荐答案

尝试以下操作:

href="<%= ResolveUrl("~/pages/page.aspx") + "?id=" + ServervariableName %>"

这仅在不添加 runat ="server" 的情况下有效.

This will only work if you do not add runat="server".

这篇关于在href&lt;%= xx%&gt;中使用服务器变量使用runat = server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆