inline codeblock doesnt run

N

Nime

This codeblock has no problem.

XXX<%= 19690 %>YYY


Next inline codeblock doesn't run below.


<asp:Image runat="server" ID="img"
ImageUrl="image.aspx?id=1&key=<%=19690 %>" />


I just wanted to write key value for the image. Any idea?
 
M

MarkD

I can reproduce your problem using a simple aspx page as below:

<%@ Page language="c#" AutoEventWireup="true" %>
<html>
<body >
<form id="Form1" method="post" runat="server" action="?<
%=Request.QueryString%>">
Query String value: <%=Request.QueryString %>
<br />
<input type=submit />
</form>
</body>
</html>

This displays the following after submitting the form:
Query String value: %3c%25=Request.QueryString%25%3e

For some reason, the inline code is not executed when the
runat="server" is present. The strange thing is I have 3 machines
that do not behave this way and one that does, so I can only assume
that this is an IIS/.NET config issue, possibly caused by a recent MS
Update. The software I have installed recently on the machine
exhibiting this behaviour is:
Visual Studio 2008
WSE 3.0
IE8 RC1

I wonder if any of these have caused this?
 
I

iduditz

<% %> are not allowed in server controls. When you embedded halfway into
your imageurl property, the compiler wasnt able to tell you the issue

<asp:image id="bla" imageurl="blabla<%= 234 %>" /> doesnt show the error but
<asp:image id="bla" imageurl="<%=234" /> does

try using an html control instead:
<img id="myimage" src="<%=123 %>" />

or use data binding
 
M

MarkD

iduditz can you point me to any MS documentation that states this? <%
%> has worked in server side controls in the web app I work on for
years, and even now works on all but one win2003 server - I just can't
work out what the difference is for this one machine, and suspect it
may be a .NET Framework update...
 
A

Andrew Morton

Is what you want simply

<asp:Image runat="server" ID="img" ImageUrl="image.aspx?id=1&key=19690" />

?

Andrew
 
M

MarkD

I've uninstalled the .NET framework while investigating this (3.5 then
3.0 and 2.0) - I then had no problems after
Installing each of the following:
..net framework 2.0
..net framework 2.0 SP1
..net framework 3.0
..net framework 3.0 SP1
..net framework 3.5

But after I installed .net framework 3.5 SP1 the behaviour returned –
I guess this is the issue. I have raised this with Microsoft and will
update this thread when I get a response.
 
N

Nime

Yes but I have to display different image every time...



I tried to use a function and set a breakpoint. That breakpoint never be hit,
I also tried to rename the function for testing purpose, then an error occured.

<asp:Image runat="server" ID="img" ImageUrl='<%# getUrl(19690) %>' />

public string getUrl(int key)
{
return "image.aspx?id=1&key=" + key; // I set breakpoint here
}
 
M

MarkD

Time will hopefully tell...

Are you able to confirm whether you have .NET Framework 3.5 SP1 (which
stealthily brings .NET 2.0 SP2)? If so, does removing it help?
 
A

Andrew Morton

Nime said:
Yes but I have to display different image every time...

Hey! Not fair: you didn't write that in the OP! ;-)

I think maybe it's time for you to discover using "code-behind", although as
it looks like you were doing so with the function, I'm not sure why you
didn't do something along the lines of

(VB.NET as I don't know C#)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
img.ImageUrl=getUrl(19690)
End Sub

Or if the required image ref was passed in the query string, something like

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
img.ImageUrl=getUrl(Request.QueryString("id"))
End Sub

Of course, you'd do input validation on the querystring.

I suspect using <% %> inside an asp: control was never actually meant to
work.

Andrew
 
M

MarkD

Andrew is partly correct - this is a known bug according to MS, code
render blocks <%...%> cannot be used for attribute values in server
controls. The problem I had was caused by this combined with the fact
that prior to .NET 2 SP2 the "action" attribute for server forms had
no effect, but after SP2 this was changed, my code render block that
had previously been ignored was suddenly eing output literally.

Details can be found here
http://stackoverflow.com/questions/...solve-in-asp-net-custom-control/564601#564601
- there are links to the connect bug report if you're interested.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top