Solved

capture the events

Posted on 2004-04-14
16
482 Views
Last Modified: 2010-04-15
how can i capture an onclick button event on OnInit or the begining of Page_load?
0
Comment
Question by:alain123
  • 7
  • 4
  • 3
  • +1
16 Comments
 
LVL 1

Author Comment

by:alain123
ID: 10826873
a dynamic created button
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10827305
What do you mean "capture onclick in OnInit"?
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10827397
                 this.reportDetail1.Init += new System.EventHandler(this.yourroutine);
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Author Comment

by:alain123
ID: 10827500
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
 
LVL 1

Author Comment

by:alain123
ID: 10827514
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
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
ID: 10827538
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
 
LVL 4

Expert Comment

by:caner_elci
ID: 10827556
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
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10827569
caner_elci, I think we are talking about an ASP.NET application. There is no MouseDown event, neither global variables
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10827613
Oh, sorry... forget my post then..
0
 
LVL 1

Author Comment

by:alain123
ID: 10827672
thanks caner =)  ..  avenger let me see if that works, brb
0
 
LVL 1

Author Comment

by:alain123
ID: 10827996
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
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10828027
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
 
LVL 1

Author Comment

by:alain123
ID: 10828100
thank you gregory, appreaciatte your help.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10828207
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
 
LVL 1

Author Comment

by:alain123
ID: 10834728
thank you gregory, i'll look into your code!

alain

0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10834759
in other words it will come as form __EVENTTARGET = ctl0:ctl1:NameGiven
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now