Identifying calls from anchors

G

Guest

I am busy doing a small application to get myself familiar with asp.net, and I have run into a problem. I have a list of anchors created with a repeater. I need to uniquely identify each anchor when doing a post back so that some data fields can be filled with the appropriate data. I have tried setting the id as follows:

<a href="#" id='<%#GetPhotoKey(Container.DataItem)%>' onserverclick='SelectAnchor_Click' runat="server"><%#GetPhotoTitle(Container.DataItem)%></a>

I get an "invalid identifier" error with the above code. Setting the name this way results in the server-side script being sent to the client.

The only other option I can think of is to reload the page (via the querystring). This brings up an entirely different problem that I would like to avoid if at all possible.

Any help would be greatly appreciated.
 
J

John Saunders

Paul K said:
I am busy doing a small application to get myself familiar with asp.net,
and I have run into a problem. I have a list of anchors created with a
repeater. I need to uniquely identify each anchor when doing a post back so
that some data fields can be filled with the appropriate data. I have tried
setting the id as follows:
<a href="#" id='<%#GetPhotoKey(Container.DataItem)%>'
onserverclick='SelectAnchor_Click'
runat="server"> said:
I get an "invalid identifier" error with the above code. Setting the name
this way results in the server-side script being sent to the client.
The only other option I can think of is to reload the page (via the
querystring). This brings up an entirely different problem that I would
like to avoid if at all possible.
Any help would be greatly appreciated.

Why not use a LinkButton, which has CommandName and CommandArgument
properties? You can arrange to have a different CommandArgument for each
item in the repeater. You can see the CommandArgument when you handle the
Command event of the LinkButton.
 
G

Guest

Thanks for the tip; the link button is exactly what I needed. I didn't really know what the purpose of it was; now I do :)

Thanks!
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top