capture the events

how can i capture an onclick button event on OnInit or the begining of Page_load?
LVL 1
alain123Asked:
Who is Participating?
 
TheAvengerConnect With a Mentor Commented:
You can check the IsPostBack property. Then at least you can know if "some" button caused a post back of the page. You can also review the Request values (Request[0], Request[1], etc. or by name) and see, somewhere the pressed button's ID should be mentioned (maybe it's Request["ButtonID"] != null)
0
 
alain123Author Commented:
a dynamic created button
0
 
TheAvengerCommented:
What do you mean "capture onclick in OnInit"?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
gregoryyoungCommented:
                 this.reportDetail1.Init += new System.EventHandler(this.yourroutine);
0
 
alain123Author Commented:
I mean when I enter OnInit, to find out if Button1 has been clicked or not ...

gregor, i'm alerady doing that, but "yourroutine" will be the last event exceuted after OnInit and Page_load ..

I want to find out if the button was clicked at the begining of the flow..
0
 
alain123Author Commented:
I create the link buttons dynamically and assign the
onClick handler, however I noticed that the Page_Load event is processed
first so I never get a chance to find out what linkbutton was clicked
until it is too late.
0
 
caner_elciCommented:
I don't know why do you need this, but try this:

Add an event handler to Button's MouseDown event.. and in MouseDown event, set a global boolean variable something like IsButtonPressed to true.. so you will be able to check it in OnInit event or whereever you want..
0
 
TheAvengerCommented:
caner_elci, I think we are talking about an ASP.NET application. There is no MouseDown event, neither global variables
0
 
caner_elciCommented:
Oh, sorry... forget my post then..
0
 
alain123Author Commented:
thanks caner =)  ..  avenger let me see if that works, brb
0
 
alain123Author Commented:
ok avenger, that was right ..       if(Request["BackButton"] != null)  works.. at least it has the name of the button when i do Request["BackButton"]  on the imm window... thanks..

alain
0
 
gregoryyoungCommented:
So sorry for the incomplete response but I was trying to guess at what you wanted since it was far from apparent in the wording of your question. The answer that it will be set on the Request object is correct though.
0
 
alain123Author Commented:
thank you gregory, appreaciatte your help.
0
 
gregoryyoungCommented:
I will however add that this methodology does not work on ALL events ...

the following is the code is created for other events


<script language="javascript">
<!--
      function __doPostBack(eventTarget, eventArgument) {
            var theform;
            if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
                  theform = document.forms["MainForm"];
            }
            else {
                  theform = document.MainForm;
            }
            theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
            theform.__EVENTARGUMENT.value = eventArgument;
            theform.submit();
      }
// -->
</script>

as you can see you can read another form field the rest of the time :)
0
 
alain123Author Commented:
thank you gregory, i'll look into your code!

alain

0
 
gregoryyoungCommented:
in other words it will come as form __EVENTTARGET = ctl0:ctl1:NameGiven
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.