472,353 Members | 994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

How To Determine What Caused PostBack

I am dynamically inserting an html <input> tag as text (equivalent of an
image button) into a page via a Literal control.

Something like this gets inserted:
<input type="image" name="MyImageButton" id="MyImageButton"
src="somePic.jpg" />

I want for the code-behind to "know" when the user clicked on the image -
but I don't want to also have to dynamically specify a delegate for an event
procedure to handle this control which is really inserted as a simple string
at runtime under limited conditions.

I was thinking/hoping that I could simply determine (somehow) in the
Page_Load event if the current PostBack was caused by a user clicking on the
image - and then take required action. So, how can I determine in Page_Load
that the current PostBack was caused by the user clicking on the
image/<input>?

Thanks!
Nov 19 '05 #1
3 2143
An HTML image input element does the same thing that an HTML submit input
element does. It submits the form. When any form element or JavaScript that
submits a form submits the form, the form doesn't contain any information
regarding what element submitted the form. Now, there are a couple of ways
to pass this information back to the server, and both of them require
JavaScript. One (the easiest) is to use a Server Control for your HTML image
input element, and to write a server-side Event Handler for it. However, you
mysteriously stated that you "don't want to also have to dynamically specify
a delegate for an event procedure to handle this control..." I find it
mysterious because you didn't state any logical justification for not
wanting to do that. It almost appears as if you have something against the
ASP.Net object-oriented programming model. The second way is to roll your
own event handler, by adding an "onclick" client-side JavaScript event
handler that puts the ID or name of the control into a hidden form field and
submits the form. On the server side, the class can then read the contents
of the hidden form field to find out what element submitted the form.
Interestingly enough, this is exactly what ASP.Net does when you use a
Server Control with an Event Handler delegate.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Jordan" <A@B.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
I am dynamically inserting an html <input> tag as text (equivalent of an
image button) into a page via a Literal control.

Something like this gets inserted:
<input type="image" name="MyImageButton" id="MyImageButton"
src="somePic.jpg" />

I want for the code-behind to "know" when the user clicked on the image -
but I don't want to also have to dynamically specify a delegate for an
event procedure to handle this control which is really inserted as a
simple string at runtime under limited conditions.

I was thinking/hoping that I could simply determine (somehow) in the
Page_Load event if the current PostBack was caused by a user clicking on
the image - and then take required action. So, how can I determine in
Page_Load that the current PostBack was caused by the user clicking on the
image/<input>?

Thanks!

Nov 19 '05 #2
<< you didn't state any logical justification for not wanting to do that>>

I'm lazy! Is that logical enough?! I was just hoping for some easier way
and I'm relatively new to Web programming in general so the specifics of how
the submits take place - as you explained - weren't understood. For all I
knew the "thing that caused the submit" was passed as a form variable or
parameter as part of the normal course of operations on the Web.

I sure appreciate your explanation and perspective - very helpful from you
as usual.

It looks like I'll have to do some work here - darn it.

: )
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
An HTML image input element does the same thing that an HTML submit input
element does. It submits the form. When any form element or JavaScript
that submits a form submits the form, the form doesn't contain any
information regarding what element submitted the form. Now, there are a
couple of ways to pass this information back to the server, and both of
them require JavaScript. One (the easiest) is to use a Server Control for
your HTML image input element, and to write a server-side Event Handler
for it. However, you mysteriously stated that you "don't want to also have
to dynamically specify a delegate for an event procedure to handle this
control..." I find it mysterious because you didn't state any logical
justification for not wanting to do that. It almost appears as if you have
something against the ASP.Net object-oriented programming model. The
second way is to roll your own event handler, by adding an "onclick"
client-side JavaScript event handler that puts the ID or name of the
control into a hidden form field and submits the form. On the server side,
the class can then read the contents of the hidden form field to find out
what element submitted the form. Interestingly enough, this is exactly
what ASP.Net does when you use a Server Control with an Event Handler
delegate.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.

"Jordan" <A@B.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
I am dynamically inserting an html <input> tag as text (equivalent of an
image button) into a page via a Literal control.

Something like this gets inserted:
<input type="image" name="MyImageButton" id="MyImageButton"
src="somePic.jpg" />

I want for the code-behind to "know" when the user clicked on the image -
but I don't want to also have to dynamically specify a delegate for an
event procedure to handle this control which is really inserted as a
simple string at runtime under limited conditions.

I was thinking/hoping that I could simply determine (somehow) in the
Page_Load event if the current PostBack was caused by a user clicking on
the image - and then take required action. So, how can I determine in
Page_Load that the current PostBack was caused by the user clicking on
the image/<input>?

Thanks!


Nov 19 '05 #3
Jordan,

Arne wrote up an innovative article on how to wire events with
reflection: http://www.jroller.com/page/CoBraLorD/20040811
which illustrates how to do it without adding a delegate explicitly. It
should be fairly easy to adapt the code to your
needs

-Stefan

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JollyK | last post by:
Hi friends, This is my question.... From the Page Load event (or Page Init event), I would need to find which event had occurred that caused a...
9
by: Joe | last post by:
I have a DataGrid with a templated column that displays ImageButtons. I need to know if one of these buttons caused the postback or just another...
5
by: Joey G | last post by:
How do I get the name or identify the control that caused the page postback. I need the information during page init. Reason why, because I need to...
5
by: TS | last post by:
Is there a way in debug mode to determine what event caused the postback to occur without having an event handler for that event? thanks
2
by: news.microsoft.com | last post by:
How can I tell which control caused a postback? I have several controls that cause a postback, and I want to take different actions depending on...
0
by: John A Grandy | last post by:
For an .aspx page that uses no server-side controls -- instead it generates all of its html and writes it to the page in the overriden render event....
14
by: Mike Collins | last post by:
In my page initialize, I am loading dynamic controls for a survey. On the survey, I have a stop button. If the user clicks the stop button, because...
0
by: =?Utf-8?B?YmVycnkubW9yZ2Fu?= | last post by:
I want to bypass my content page's page_load event when the postback is caused by a control from my masterpage, doing something like this from my...
3
by: | last post by:
Hi all, I have a CheckBoxList control which has about 10 items. I have set autopostback=true and also set an eventhandler for...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.