1

Is there any way to allow me to trace button click in which webpage.

For example Default1.aspx button1 click

Then in my log file.My log file will log that button1 click in default1 page .

Is possible to do this in the beginrequest event of the global.asax file? Please guild me a solution .

Here is my code for global.asax

 protected void Application_Start(object sender, EventArgs e)
    {

        // Set logfile name and application name variables

        string l4net = Server.MapPath("~/log4Net.config");
        log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(l4net));


    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        //What should i code here???

    }

Any help is much appreciated

user998405
  • 1,329
  • 5
  • 41
  • 84

1 Answers1

0

Yes, surely you can do it.

You can get the current page using

var page = HttpContext.Current.Request.Url;

and the button is present in the event target

var button = HttpContext.Current.Request.Params["__EVENTTARGET"];

This gets you the ClientID of your control, but you should be able to extract the control ID from it.

nunespascal
  • 17,584
  • 2
  • 43
  • 46
  • Thanks ya. Btw what u means extract the control ID? – user998405 Sep 03 '12 at 04:12
  • I try adi . I only able to get the current page. I not able to get which button has been clicked :( – user998405 Sep 03 '12 at 04:20
  • `ClientID` is a field generated by asp.net for controls that are nested in containers. Often if your button is called `Btn1` say in `Panel1`, the CliendID could look like `ct100_Panel1_Btn1` – nunespascal Sep 03 '12 at 04:21
  • Debug and inspect the `HttpContext.Current.Request.Params` collection. If you clicked a button, the `__EVENTTARGET` should be present. – nunespascal Sep 03 '12 at 04:24
  • The __EVENTTARGET only return me null value :( – user998405 Sep 03 '12 at 04:26
  • Ok . thanks . I get the value only. The problem I cannot get the value is because I click the button which response redirect to other page. Thanks very much – user998405 Sep 03 '12 at 04:28