开发者

My <% %> not working in div. Why?

I've tried both snippets below. Nothing. I've tried <%#, <%=, and <%. Nothing. So I'm stuck.

<div style="background-color:Gray; color:white; text-align:center; width:100%;">
            <asp:HyperLink ID="HyperLink1" Target="_blank"  NavigateUrl='<%= Server.HtmlEncode(String.Format("~/ShowHistory.aspx?section={0}&jobnumber={1}", "APQP Header", "101244")) %>' runat="server">Show Updated History</asp:HyperLink>&nbsp;&nbsp;
            <asp:HyperLink Target="_blank" NavigateUrl="~/ShowDeletedHistory.aspx" ID="HyperLink2" runat="server">Show Deleted History</asp:HyperLink></div>
        <br />

<div style="background-color:Gray; color:white; text-align:center; width:100%;">
            <asp:HyperLink ID="HyperLink1" Target="_blank"  NavigateUrl='<%= String.Format("~/ShowHistory.aspx?section={0}开发者_如何学Python&jobnumber={1}", "APQP Header", "101244") %>' runat="server">Show Updated History</asp:HyperLink>&nbsp;&nbsp;
            <asp:HyperLink Target="_blank" NavigateUrl="~/ShowDeletedHistory.aspx" ID="HyperLink2" runat="server">Show Deleted History</asp:HyperLink></div>
        <br />


Try <%# ... %> and call this.DataBind() (or Me.DataBind()) when your page loads.


Server controls cannot contain this type of tags. The reason is that "<%= %>" is basically equal to Response.Write, which itself executes after the page has gone through its lifecycle, when the response is already constructed. If you use it when setting a value of a server-side control property, this value has to be resolved when (or a little after) parsing the page markup. This is the reason you cannot use "<%= %>" in a server control.

If it was a normal html tag, it would work, but the virtual URL would not.

Is there a reason you're not setting the NavigationUrl in code? It would look much nicer to me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜