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

Signature
dchillman
Marina - 18 Oct 2005 20:33 GMT
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.
> string ctrlname = page.Request.Params.Get("__EVENTTARGET");
> if (ctrlname != null && ctrlname != string.Empty)
[quoted text clipped - 31 lines]
>
> Thanks
dchillman - 18 Oct 2005 20:49 GMT
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

Signature
dchillman
> Why do you need to figure this out?
>
[quoted text clipped - 36 lines]
> >
> > Thanks
Bruce Barker - 18 Oct 2005 21:49 GMT
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)
> string ctrlname = page.Request.Params.Get("__EVENTTARGET");
> if (ctrlname != null && ctrlname != string.Empty)
[quoted text clipped - 31 lines]
>
> Thanks
dchillman - 19 Oct 2005 13:28 GMT
Can you elaborate on what you mean by "recreate the controls first for
FindControl to work"?
thanks

Signature
dchillman
> Request.Params.Get("__EVENTTARGET") returns the name that FindControl
> expects. but you need to recreate the controls first for FindContol to work.
[quoted text clipped - 38 lines]
> >
> > Thanks