Determining control that caused a postback

Discussion in 'ASP .Net' started by =?Utf-8?B?ZGNoaWxsbWFu?=, Oct 18, 2005.

  1. string ctrlname = page.Request.Params.Get("__EVENTTARGET");
    if (ctrlname != null && ctrlname != string.Empty)
    {
    return this.Page.FindControl(ctrlname);
    }


    I have a form on which I was trying to determine which user-action caused a
    postback. In various places I found the code above that works for most
    controls.

    The problem I have been having is with radiobutton list control. A value
    for "ctrlname" will be found, but this.Page.FindControl(ctrlname) returns a
    null value. The problem appears to be related to the value for ctrlname that
    is returned. Its construction appears to be related to the type of control.
    Dropdown list controls seem to have the format
    pagename:controlname
    while my radiobutton list control has the format
    pagename_controlname_n, where n is 1, 2, 3, ....

    For my needs, I wrote code to extract the real control name which is then
    passed to the Page.FindControl method.

    My question has to do with the values returned by

    page.Request.Params.Get("__EVENTTARGET");

    Are there rules for how it constructs the value it returns for each type of
    control, and if so, where can I find them?

    Thanks


    --
    dchillman
     
    =?Utf-8?B?ZGNoaWxsbWFu?=, Oct 18, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?ZGNoaWxsbWFu?=

    Marina Guest

    Why do you need to figure this out?

    Handle the events of the various controls, the click for the buttons,
    selectedindexchanged for the dropdowns, etc.

    "dchillman" <> wrote in message
    news:...
    > string ctrlname = page.Request.Params.Get("__EVENTTARGET");
    > if (ctrlname != null && ctrlname != string.Empty)
    > {
    > return this.Page.FindControl(ctrlname);
    > }
    >
    >
    > I have a form on which I was trying to determine which user-action caused
    > a
    > postback. In various places I found the code above that works for most
    > controls.
    >
    > The problem I have been having is with radiobutton list control. A value
    > for "ctrlname" will be found, but this.Page.FindControl(ctrlname) returns
    > a
    > null value. The problem appears to be related to the value for ctrlname
    > that
    > is returned. Its construction appears to be related to the type of
    > control.
    > Dropdown list controls seem to have the format
    > pagename:controlname
    > while my radiobutton list control has the format
    > pagename_controlname_n, where n is 1, 2, 3, ....
    >
    > For my needs, I wrote code to extract the real control name which is then
    > passed to the Page.FindControl method.
    >
    > My question has to do with the values returned by
    >
    > page.Request.Params.Get("__EVENTTARGET");
    >
    > Are there rules for how it constructs the value it returns for each type
    > of
    > control, and if so, where can I find them?
    >
    > Thanks
    >
    >
    > --
    > dchillman
     
    Marina, Oct 18, 2005
    #2
    1. Advertising

  3. new to the asp.net world, so pardon my ignorance. I have a radiobutton list
    control, a couple dropdown list controls, and a grid control on the form.
    When the user selects items from the list controls, the grid would update
    with the proper data. Originally I was handling loading the proper data into
    the controls during the postback and wanted to know which one caused the
    post-back, so I could take different action during the post-back. I think I
    just started down this path and just didn't see the simpler solution. Thanks
    for pointing me back in the right direction.

    For curiosity sake, I still am wondering if there are rules to the value
    returned by

    page.Request.Params.Get("__EVENTTARGET");


    thanks
    --
    dchillman


    "Marina" wrote:

    > Why do you need to figure this out?
    >
    > Handle the events of the various controls, the click for the buttons,
    > selectedindexchanged for the dropdowns, etc.
    >
    > "dchillman" <> wrote in message
    > news:...
    > > string ctrlname = page.Request.Params.Get("__EVENTTARGET");
    > > if (ctrlname != null && ctrlname != string.Empty)
    > > {
    > > return this.Page.FindControl(ctrlname);
    > > }
    > >
    > >
    > > I have a form on which I was trying to determine which user-action caused
    > > a
    > > postback. In various places I found the code above that works for most
    > > controls.
    > >
    > > The problem I have been having is with radiobutton list control. A value
    > > for "ctrlname" will be found, but this.Page.FindControl(ctrlname) returns
    > > a
    > > null value. The problem appears to be related to the value for ctrlname
    > > that
    > > is returned. Its construction appears to be related to the type of
    > > control.
    > > Dropdown list controls seem to have the format
    > > pagename:controlname
    > > while my radiobutton list control has the format
    > > pagename_controlname_n, where n is 1, 2, 3, ....
    > >
    > > For my needs, I wrote code to extract the real control name which is then
    > > passed to the Page.FindControl method.
    > >
    > > My question has to do with the values returned by
    > >
    > > page.Request.Params.Get("__EVENTTARGET");
    > >
    > > Are there rules for how it constructs the value it returns for each type
    > > of
    > > control, and if so, where can I find them?
    > >
    > > Thanks
    > >
    > >
    > > --
    > > dchillman

    >
    >
    >
     
    =?Utf-8?B?ZGNoaWxsbWFu?=, Oct 18, 2005
    #3
  4. =?Utf-8?B?ZGNoaWxsbWFu?=

    Bruce Barker Guest

    Request.Params.Get("__EVENTTARGET") returns the name that FindControl
    expects. but you need to recreate the controls first for FindContol to work.

    note: the button and imagebutton controls do not use _EVENTTARGET

    -- bruce (sqlwork.com)



    "dchillman" <> wrote in message
    news:...
    > string ctrlname = page.Request.Params.Get("__EVENTTARGET");
    > if (ctrlname != null && ctrlname != string.Empty)
    > {
    > return this.Page.FindControl(ctrlname);
    > }
    >
    >
    > I have a form on which I was trying to determine which user-action caused
    > a
    > postback. In various places I found the code above that works for most
    > controls.
    >
    > The problem I have been having is with radiobutton list control. A value
    > for "ctrlname" will be found, but this.Page.FindControl(ctrlname) returns
    > a
    > null value. The problem appears to be related to the value for ctrlname
    > that
    > is returned. Its construction appears to be related to the type of
    > control.
    > Dropdown list controls seem to have the format
    > pagename:controlname
    > while my radiobutton list control has the format
    > pagename_controlname_n, where n is 1, 2, 3, ....
    >
    > For my needs, I wrote code to extract the real control name which is then
    > passed to the Page.FindControl method.
    >
    > My question has to do with the values returned by
    >
    > page.Request.Params.Get("__EVENTTARGET");
    >
    > Are there rules for how it constructs the value it returns for each type
    > of
    > control, and if so, where can I find them?
    >
    > Thanks
    >
    >
    > --
    > dchillman
     
    Bruce Barker, Oct 18, 2005
    #4
  5. Can you elaborate on what you mean by "recreate the controls first for
    FindControl to work"?

    thanks
    --
    dchillman


    "Bruce Barker" wrote:

    > Request.Params.Get("__EVENTTARGET") returns the name that FindControl
    > expects. but you need to recreate the controls first for FindContol to work.
    >
    > note: the button and imagebutton controls do not use _EVENTTARGET
    >
    > -- bruce (sqlwork.com)
    >
    >
    >
    > "dchillman" <> wrote in message
    > news:...
    > > string ctrlname = page.Request.Params.Get("__EVENTTARGET");
    > > if (ctrlname != null && ctrlname != string.Empty)
    > > {
    > > return this.Page.FindControl(ctrlname);
    > > }
    > >
    > >
    > > I have a form on which I was trying to determine which user-action caused
    > > a
    > > postback. In various places I found the code above that works for most
    > > controls.
    > >
    > > The problem I have been having is with radiobutton list control. A value
    > > for "ctrlname" will be found, but this.Page.FindControl(ctrlname) returns
    > > a
    > > null value. The problem appears to be related to the value for ctrlname
    > > that
    > > is returned. Its construction appears to be related to the type of
    > > control.
    > > Dropdown list controls seem to have the format
    > > pagename:controlname
    > > while my radiobutton list control has the format
    > > pagename_controlname_n, where n is 1, 2, 3, ....
    > >
    > > For my needs, I wrote code to extract the real control name which is then
    > > passed to the Page.FindControl method.
    > >
    > > My question has to do with the values returned by
    > >
    > > page.Request.Params.Get("__EVENTTARGET");
    > >
    > > Are there rules for how it constructs the value it returns for each type
    > > of
    > > control, and if so, where can I find them?
    > >
    > > Thanks
    > >
    > >
    > > --
    > > dchillman

    >
    >
    >
     
    =?Utf-8?B?ZGNoaWxsbWFu?=, Oct 19, 2005
    #5
    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. RTM
    Replies:
    4
    Views:
    2,798
    mikeb
    Jan 20, 2004
  2. Nathan Sokalski

    Determining What Control Caused The PostBack

    Nathan Sokalski, Sep 5, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    949
    Nathan Sokalski
    Sep 5, 2005
  3. Nathan Sokalski

    Determining What Control Caused The PostBack

    Nathan Sokalski, Sep 5, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    147
    Nathan Sokalski
    Sep 5, 2005
  4. Nathan Sokalski

    Determining What Control Caused The PostBack

    Nathan Sokalski, Sep 5, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    185
    Nathan Sokalski
    Sep 5, 2005
  5. matthias s

    determining what control caused the click event

    matthias s, Sep 19, 2007, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    194
    David R. Longnecker
    Sep 20, 2007
Loading...

Share This Page