[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

capture the events

how can i capture an onclick button event on OnInit or the begining of Page_load?
0
alain123
Asked:
alain123
  • 7
  • 4
  • 3
  • +1
1 Solution
 
alain123Author Commented:
a dynamic created button
0
 
TheAvengerCommented:
What do you mean "capture onclick in OnInit"?
0
 
gregoryyoungCommented:
                 this.reportDetail1.Init += new System.EventHandler(this.yourroutine);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
TheAvengerCommented:
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
 
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 7
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now