<% ... %> constructs?

Discussion in 'ASP .Net' started by Martin Schmid, May 2, 2004.

  1. 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
     
    Martin Schmid, May 2, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Mark Fitzpatrick, May 2, 2004
    #2
    1. Advertising

  3. Martin Schmid

    manoj.bca

    Joined:
    Sep 30, 2006
    Messages:
    1
    thank u Mark Fitzpatrick, your trick worked for me. i was searching for this. thanks a lot.
     
    manoj.bca, Sep 30, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcos MOS
    Replies:
    5
    Views:
    15,821
    Bruno Sirianni
    Apr 15, 2004
  2. Web Science
    Replies:
    0
    Views:
    315
    Web Science
    Nov 16, 2004
  3. Neil Zanella
    Replies:
    1
    Views:
    5,042
    Philip Q [MVP]
    Jan 12, 2005
  4. Web Science
    Replies:
    0
    Views:
    347
    Web Science
    Nov 16, 2004
  5. Landrew

    Constructs

    Landrew, Dec 11, 2004, in forum: C++
    Replies:
    4
    Views:
    437
    Niels Dekker - no reply address
    Dec 12, 2004
Loading...

Share This Page