By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,776 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,776 IT Pros & Developers. It's quick & easy.

<% ... %> constructs?

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Martin Schmid" <ma**********@sbcglobal.net.nospam> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.