I just found the most weird behavior I have seen in ASP.NET yet and thought I'd share my confusion:
What I wanted to do was to create a script inside a popup that after a postback redirects the opener:
I first tried this by simply creating a Literal control and setting its text to the string above, but even if I set Mode="PassThrough" it still converts the "&" to "&". Some comments I found online said that's how it should be, but however that might be, it doesn't work, the page the main window gets set to (in Firefox at least) is one without the "other" parameter.
Some other comment mentioned using the "<%= %>" syntax instead. I tried this, and the "&" got encoded there, too.
I finally found a solution by accident, and that's where it gets really weird: If I include both the literal and right after that the "<%= %>" asp-syntax, then the "&" doesn't get encoded in the asp-block. If the literal is missing, is set to Visible="false" or doesn't have the javascript-string assigned then the "&" is encoded again in the asp-block. I can only guess that by being assigned to the literal the string somehow gets marked as *has been encoded* internally (while it actually hasn't been) and because of that isn't encoded when it's used in the asp-block.
Does anyone have an idea if there's a way to get that unencoded "&" there in a better way, without relying on what seems to be an ASP.NET-bug?
What I wanted to do was to create a script inside a popup that after a postback redirects the opener:
Code:
<script type="text/javascript">
opener.location='http://mysite/page?param=x&other=y';
</script>
I first tried this by simply creating a Literal control and setting its text to the string above, but even if I set Mode="PassThrough" it still converts the "&" to "&". Some comments I found online said that's how it should be, but however that might be, it doesn't work, the page the main window gets set to (in Firefox at least) is one without the "other" parameter.
Some other comment mentioned using the "<%= %>" syntax instead. I tried this, and the "&" got encoded there, too.
I finally found a solution by accident, and that's where it gets really weird: If I include both the literal and right after that the "<%= %>" asp-syntax, then the "&" doesn't get encoded in the asp-block. If the literal is missing, is set to Visible="false" or doesn't have the javascript-string assigned then the "&" is encoded again in the asp-block. I can only guess that by being assigned to the literal the string somehow gets marked as *has been encoded* internally (while it actually hasn't been) and because of that isn't encoded when it's used in the asp-block.
Does anyone have an idea if there's a way to get that unencoded "&" there in a better way, without relying on what seems to be an ASP.NET-bug?