1) Why use a WebServer Control such as the ImageButton if you want to
handle the event on the client side?
Use an HTML Image set as a Server Control and in your Page_Load method or in
a method called from Page_Load, do something like this:
myImage.Attributes.Add("onclick", "theNameOfMyClientSideJavaScriptMethod(\""
+ myVariablePathName
+ \"")";
2) To read the file system into a string array and DataBind your DataList
to it:
// for demonstration purposes, use the path that this web app is running
from
// but you may want to use a different path. If so, just make sure that the
// account that your web app is running under has access to read the
directory.
string myPath = Request.PhysicalApplicationPath;
string[] strArray =
System.IO.Directory.GetFiles(myPath,"*.gif");
DataList1.DataSource = strArray;
DataList1.DataBind();
Then, in the ASPX file, to display the image associated with the path given:
<ASP:DATALIST ID="DataList1" RUNAT="server">
<ITEMTEMPLATE>
<img src="<%# Container.DataItem %>">;
</ITEMTEMPLATE>
</ASP:DATALIST>
HTH
DalePres
MCAD, MCDBA, MCSE
"David P. Donahue" <dd******@ccs.neu.edu> wrote in message
news:Oj**************@TK2MSFTNGP10.phx.gbl...
This is a 2-part question:
1) I have a web form with multiple ImageButtons on it. I'd like them all
to do the same thing. Basically, in english-code, the function would be
as follows:
Set Session variable X to the ImageURL of the button that invoked me;
Forward the user to a specific URL;
That code is the easy part, of course. I just need to know how to tell
the ImageButtons to call that function when they're clicked. Preferably
within the HTML-view instead of the code-behind in Visual Studio.
2) Is there a way to have a control on a page (like a Repeater or
DataList) where I can give it a directory and a file mask of some kind and
it will make a list of ImageButtons, where each one's ImageURL is a
matching file in the directory, and set them all to use a specific
function as in part 1 above? I'm just looking for a way to speed up
development of something that's going to involve many, many very similar
pages.
Any help would be greatly appreciated. Thank you.
Regards,
David P. Donahue
dd******@ccs.neu.edu