<% ... %> constructs?

M

Martin Schmid

I'm getting a parser error message:
Server tags cannot contain <% ... %> constructs...

Ok.. so How do I accomplish this:

For Each file in Files
if ucase(right(file.name,7))<>ucase("_tn.jpg") and
ucase(right(file.name,4))=ucase(".jpg") then
tnName=left(file.name,len(file.name)-4) & "_tn.jpg"%>
<asp:imagebutton runat="server" ImageUrl=<%=tnName%> onClick="IB_Click"/>



Thx,
MS
 
M

Mark Fitzpatrick

That's correct. Remember, in ASP that worked because you were just
processing script in a page. In ASP.Net this doesn't work as well because
it's evaluating controls and events at once. You can't dynamically
response.write code into a control like this since they are both being
evaluated at the same time and it can't know which to evaluate first, the
response.write that you're dumping into the ImageUrl of the control itself.
It's tricky getting out of the ASP way of doing things but since this is
truly object-oriented now you can access the properties of this
programatically. Assign an id to the imagebutton (such as <asp:imagebutton
id="myButton"..... then you can just call the code myButton.ImageUrl =
tnName.

Of course, if you're doing a loop this isn't going to work. You'll need to
use another construct of some sort, such as a table where you can create
rows, create a new imagebutton programatically, then add it to the table row
before adding it to the cell like so:

<asp:table runat="server" id="myTable" />

Then in code behind or in the aspx page itself you can put this code into
the Page_Load event or another appropriate event. (the code sample below is
in C#, but should translate easily into VB)

// insert your loop code For Each then the following
TableRow trRow = new TableRow();
TableCell tcCell = new TableCell();
ImageButton myImage = new ImageButton();
myImage.ImageUrl = tnName;
myImage.Click += new ImageClickEventHandler(IB_Click);
tcCell.Controls.Add(myImage);
trRow.Cells.Add(tcCell);
myTable.Rows.Add(myTable);


Hope this helps,
Mark Fitzpatrick
Microsoft MVP -FrontPage
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top