473,387 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 2200
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 PostBack, for example was it a event fired from...
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 button on the form. If one of these buttons caused...
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 tell usercontrol_1 that usercontrol_2 button was...
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 which was activated. It seems a little backward...
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. How to write logic for the Page_Load() 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 of the page life cycle, the initialize and page...
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 content page's page_load handler: Private Sub...
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 OnSelectedIndexChanged. The problem is I want to identify which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...

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.