__doPostBack and arguments

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZQ==?=, Nov 18, 2004.

  1. Hi,

    I am using the following code in the page class:

    this.Button1.Attributes["onclick"] = this.Page.GetPostBackClientEvent(this,
    "MyButton1");

    When the Page_Load fires, the arguments ("e" variable) are always empty and
    the sender is always the form itself. I need to figure out which control
    caused the postback to occur, because I have some relate process.

    Any help is appreciated. Thanks.
    Mike
     
    =?Utf-8?B?TWlrZQ==?=, Nov 18, 2004
    #1
    1. Advertising

  2. The page load event will always fire, even for a post back.

    The most common way i've seen it done is this

    in page_load

    you just put

    if(!page.ispostback)
    {
    do stuff you want to happen only the first time the page loads
    }

    then put your code in the code behind the button or whatever
    on the postback, the page load stuff gets skipped and then your
    button_onclick code fires normally




    "Mike" wrote:

    >
    > Hi,
    >
    > I am using the following code in the page class:
    >
    > this.Button1.Attributes["onclick"] = this.Page.GetPostBackClientEvent(this,
    > "MyButton1");
    >
    > When the Page_Load fires, the arguments ("e" variable) are always empty and
    > the sender is always the form itself. I need to figure out which control
    > caused the postback to occur, because I have some relate process.
    >
    > Any help is appreciated. Thanks.
    > Mike
    >
    >
     
    =?Utf-8?B?YWRvbGYgZ2FybGlj?=, Nov 18, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?TWlrZQ==?=

    Jason Kester Guest

    "Mike" <> wrote in message news:<>...
    > this.Button1.Attributes["onclick"] = this.Page.GetPostBackClientEvent(this,
    > "MyButton1");
    >
    > When the Page_Load fires, the arguments ("e" variable) are always empty and
    > the sender is always the form itself. I need to figure out which control
    > caused the postback to occur, because I have some relate process.


    I take it you have multiple buttons pointed at the same handler? If
    sender & eventargs are failing you, you could skip the middle man and
    inspect the __EVENTTARGET & __EVENTARGUMENT values directly.

    Request["__EVENTTARGET"] should get you the ID that the button was
    rendered to the page with.


    Jason
    http://www.expatsoftware.com/
     
    Jason Kester, Nov 18, 2004
    #3
  4. Phantastic! I skipped the middle man and it works as you said :)

    I also found an alternative solution with a hidden field. Set the value of
    the hidden field and then read it on the server side. But I like better your
    solution.

    Thanks.
    Mike



    "Jason Kester" wrote:

    > "Mike" <> wrote in message news:<>...
    > > this.Button1.Attributes["onclick"] = this.Page.GetPostBackClientEvent(this,
    > > "MyButton1");
    > >
    > > When the Page_Load fires, the arguments ("e" variable) are always empty and
    > > the sender is always the form itself. I need to figure out which control
    > > caused the postback to occur, because I have some relate process.

    >
    > I take it you have multiple buttons pointed at the same handler? If
    > sender & eventargs are failing you, you could skip the middle man and
    > inspect the __EVENTTARGET & __EVENTARGUMENT values directly.
    >
    > Request["__EVENTTARGET"] should get you the ID that the button was
    > rendered to the page with.
    >
    >
    > Jason
    > http://www.expatsoftware.com/
    >
     
    =?Utf-8?B?TWlrZQ==?=, Nov 19, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2xhcw==?=
    Replies:
    0
    Views:
    1,512
    =?Utf-8?B?Q2xhcw==?=
    Nov 10, 2005
  2. GaryDean

    __doPostBack Arguments question

    GaryDean, Apr 9, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    6,864
    Steven Cheng[MSFT]
    Apr 12, 2006
  3. Nathan Sokalski
    Replies:
    1
    Views:
    909
    Gregory A. Beamer
    Jan 11, 2010
  4. Serg

    __doPostBack and NULL __EVENTTARGET?

    Serg, Mar 3, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    430
  5. Nathan Sokalski
    Replies:
    1
    Views:
    863
    Gregory A. Beamer
    Jan 11, 2010
Loading...

Share This Page