开发者

String.Format in .aspx not showing rest of text after

<div visible="false" runat="server"><a href='<%#string.Format("{0}removeAllItems=true", this.Page)%>' onclick="return confirm('Are you sure you want to remove all items?')">Remove all items</a></div>   
开发者_如何学Python

when I run this, it doesn't show the querystring portion, just the page.aspx. I don't see why the rest of that string after {0} is being cut off.


The problem with the question mark probably has something to do with using data binding (<%#...%>) instead of simple output (<%=...%>).

String.Format is overkill, as you only want to concatenate two strings:

<a href='<%=String.Concat(this.Page, ".aspx?removeItems=true")%>' >text</a>

Or simply putting the second string in the markup:

<a href='<%=this.Page%>.aspx?removeItems=true' >text</a>


Your string concatenation is unnecessary; have you tried this?

<a href='<%#string.Format("{0}.aspx?removeItems=true", this.Page)%>' >text</a>


Since it's ignoring the ?, try this:

<a href='<%#string.Format("{0}.aspx{1}removeItems=true", this.Page, "?")%>' >text</a>

The inline tag <%# is used for databinding, yet this.
Page isn't a databound property. Switch that out to <%=, which is equivalent to Response.Write & see if that works.

It's hackish, but sometimes that's what it takes in asp.net.

E.g. if you're using StringBuilder to create a javascript string at runtime and you try StringBuilder.AppendFormat, you can't have any other braces besides the Format braces. you can overcome that problem in a similar fashion to my answer using one string.format method and injecting "{" and "}".

The "?" issue may be a problem of codepage error handling withing databinding tags. For more information on this, see: http://support.microsoft.com/kb/893663

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜