Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

Determining control that caused a postback

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dchillman - 18 Oct 2005 19:36 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.