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.ne u.edu 3 1349
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.Attribu tes.Add("onclic k", "theNameOfMyCli entSideJavaScri ptMethod(\""
+ myVariablePathN ame
+ \"")";
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.Physica lApplicationPat h;
string[] strArray =
System.IO.Direc tory.GetFiles(m yPath,"*.gif");
DataList1.DataS ource = strArray;
DataList1.DataB ind();
Then, in the ASPX file, to display the image associated with the path given:
<ASP:DATALIST ID="DataList1" RUNAT="server">
<ITEMTEMPLATE >
<img src="<%# Container.DataI tem %>">;
</ITEMTEMPLATE>
</ASP:DATALIST>
HTH
DalePres
MCAD, MCDBA, MCSE
"David P. Donahue" <dd******@ccs.n eu.edu> wrote in message
news:Oj******** ******@TK2MSFTN GP10.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.ne u.edu
> 1) Why use a WebServer Control such as the ImageButton if you want to handle the event on the client side?
Mostly because I have some additional security that must be put in place
on the server side, and having the server-side and client-side code
intermingling may work, but wouldn't give me the confidence that I need
in the security implementation. In this particular case, the security
needs outweigh the minor performance hit. Not to mention that the only
way I know how to pass values from page to page on the client side is
through a URL query string, which is just ugly :)
Your code for part 2 of my question looks great, that will definitely be
the way to go in this case. The only thing now is putting something in
the DataList's ItemTemplate that tells the image to run a server-side
function when the image is clicked (html image or asp image button,
whatever's easier to point to a server-side function). And, from within
that function, be able to access the properties of the specific image
(its SRC or its ImageURL) that was clicked.
Regards,
David P. Donahue dd******@ccs.ne u.edu
Create your event handler as follows. Make sure you set the accessibility
to protected as shown.
protected void ImageButtonClic k(object sender,
System.Web.UI.I mageClickEventA rgs e)
{
Response.Write( "the image was clicked");
}
Then, in the aspx file, add this attribute within your <ASP:IMAGEBUTTO N >
tag:
ONCLICK="ImageB uttonClick"
HTH
DalePres
MCAD, MCDBA, MCSE\
"David P. Donahue" <dd******@ccs.n eu.edu> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. .. 1) Why use a WebServer Control such as the ImageButton if you want to handle the event on the client side?
Mostly because I have some additional security that must be put in place on the server side, and having the server-side and client-side code intermingling may work, but wouldn't give me the confidence that I need in the security implementation. In this particular case, the security needs outweigh the minor performance hit. Not to mention that the only way I know how to pass values from page to page on the client side is through a URL query string, which is just ugly :)
Your code for part 2 of my question looks great, that will definitely be the way to go in this case. The only thing now is putting something in the DataList's ItemTemplate that tells the image to run a server-side function when the image is clicked (html image or asp image button, whatever's easier to point to a server-side function). And, from within that function, be able to access the properties of the specific image (its SRC or its ImageURL) that was clicked.
Regards, David P. Donahue dd******@ccs.ne u.edu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Roland Hall |
last post by:
Is there a way to return multiple values from a function without using an
array? Would a dictionary object work better?
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -...
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.09.2004
Hello,
I need to implement a library containing a hierarchy of classes
together with some binary operations on objects. To fix attention,
let me assume that it is a hierarchy of algebraic matrices with the
addition operation. Thus, I want to have a virtual base class
class Matr;
|
by: Martin |
last post by:
Hi,
I want to use Imagebuttons () to submit a form, as following:
<form ....>
<Input name="buttonEdit" type=Image onclick="ActionHandle("2")>
<Input name="buttonnew" type=Image onclick="ActionHandle("1")>
</form>
But when I click a button, the function ActionHandle is not call.
I want to know, which button the user click, to open the corresponding form
|
by: Richard Hunt |
last post by:
What is the best way to get two values back from a function?
I am working through 'The C Programming Language', but I felt
like taking a bit of time off to write another program.
The program has global variables:
extern FILE *fp;
extern Entry *start;
Entry is defined by:
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if ((someString.IndexOf("something1",0) >= 0) ||
((someString.IndexOf("something2",0) >= 0) ||
| |
by: Lau Lei Cheong |
last post by:
Hello,
Let's say that I have multiple submit buttons on a form (imagebuttons
actually, but documentations say that <input type=image> which a called
image buttons should behave like submit buttons). How could I determine
which submit button do I invoked by calling form.submit() in javascript?
Thanks a lot.
Regards,
|
by: charliewest |
last post by:
I am dynamically creating my datagrid, building each column in real-time via
code-behind (using c#).
The only way i have read to add ImageButtons to my grid dynamically is by
creating a separate template class. However, a class cannot create server
controls (or at least this is beyond me).
I am able to create HTML <INPUT> form elements, however, these are not wired
to my datagrid and hence, when clicked do not fire the datagrid's...
|
by: iporter |
last post by:
I wonder if anyone can clear up an OOP issue for me, specifically, how
to have multiple child objects of a parent object. Consider the code
below:
var parentObj={
childCount: 0,
childObj: {
id:false,
init: function() {
alert(this.id);
|
by: grbCPPUsr |
last post by:
I am new to Python. I would like to use Python for the specialized purpose of dynamic expressions parsing & evaluation in my C++ application.
I would like to encapsulate the expressions to be evaluated in Python function & compile that function at runtime, somewhat as below.
Expression to eval put in Python function
def isSizeSmall(size,vol,ADV,prod):
if ( (size < 1000) & (vol < (0.001 * ADV)) & (prod=="Stock")): print "OK"; return 10
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |