如果我添加runat =“"服务器",href单击问题; asp.net中的属性 [英] href click problem if i add runat="server" attribute in asp.net
问题描述
这是aspx页面上的一个href
here is one href on aspx page
ASPX:
<a id="hrfReport" href="<%=sApplicationURL%>Reports.aspx">Report</a>
代码隐藏:
sApplicationURL = "http://localhost/";
现在,如果我单击重定向到报告页面的href页面,但是如果我添加runat ="server"属性,则href单击不起作用.实际上,我想在特定条件下将其禁用.
now if i click on href page redirected to the reports page but if i add runat="server" attribute then href click not worked.actually i want to make it disable on particular condition.
有人知道怎么做吗?
推荐答案
您不能在服务器标签中使用<%=someVal%>
构造.编译器基本上将其翻译为Response.Write(someVal)
.
You cannot use the <%=someVal%>
construct in server tags. The compiler basically translates that to Response.Write(someVal)
.
您可以使用<%#someVal%>
构造,但是需要DataBind()
值.例如:
You can use the <%#someVal%>
construct, but you are required to DataBind()
the value. For example:
ASPX:
<a id="hrfReport" href='<%#sApplicationURL + "Reports.aspx"%>' runat="server">Report</a>
代码隐藏:
sApplicationURL = "http://localhost/";
hrfReport.DataBind();
或者...
如果有服务器控件,则可以从后面的代码中设置其属性,如下所示:
If you have a server control, you can set its properties from the code behind as follows:
ASPX:
<a id="hrfReport" runat="server">Report</a>
代码隐藏:
hrfReport.HRef = sApplicationURL + "Reports.aspx";
这篇关于如果我添加runat =“"服务器",href单击问题; asp.net中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!