473,730 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="MyImageBu tton" id="MyImageButt on"
src="somePic.jp g" />

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 2220
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******** ******@TK2MSFTN GP10.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="MyImageBu tton" id="MyImageButt on"
src="somePic.jp g" />

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***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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******** ******@TK2MSFTN GP10.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="MyImageBu tton" id="MyImageButt on"
src="somePic.jp g" />

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
4061
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 the datagrid that caused a postback, or was it from a linkbutton, or was it from any other control on the page that have PostBack capabilities ? I am pretty sure this information is captured somewhere before the event is sent to its appropiate...
9
7512
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 the postback than I don't want to do a DataBind otherwise I do. I know __EVENTTARGET doesn't return this information. Is there anything else that does? Thanks, Joe
5
5042
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 clicked and therefore need usercontrol_2 public properties to be passed to usercontrol_1 public properties in the case of the event. thanks
5
4285
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
1583
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 that the page load runs first, then last is the actual event that caused the postback, as that last event is where all the new parameters are. If I can tell what caused the postback, then I can at least take action accordingly. Or should I be...
0
962
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 which determines which control triggerred the postback ? Assume that all html controls rendered are given a name and id property , but also assume that the set of controls rendered is dynamically selected. I found a post that addresses some...
14
1945
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 load events run before the button click and reloads a bunch of controls. Is there a way to keep these events from running with a button control. The click event of the button has code to save the user's place in the survey and I only want it to...
0
1528
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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles page.Load If NOT sender.ThisEventWasFiredFromTheMasterPage then 'process normally end if
3
3490
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 checkbox item caused the event to fire to perform some routines based upon the value of that individual checkbox. How can I determine this? For example, 5 of the 10 items maybe checked. However, when I uncheck one, I want to perform some code based...
0
8943
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, 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...
0
8770
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9442
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, 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...
0
8184
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6030
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();...
0
4543
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...
0
4801
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2175
bsmnconsultancy
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...

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.