1        public static string GetControlValueFromRequest(string controlId)
 2        {
 3            if (controlId == null)
 4                throw new ArgumentNullException("controlId");
 5            string requestValue = null;
 6            HttpRequest req = HttpContext.Current.Request;
 7            string eventTarget = req.Form["__EVENTTARGET"?? string.Empty;
 8            if (eventTarget.Equals(controlId, StringComparison.InvariantCultureIgnoreCase))
 9            {
10                requestValue = req.Form["__EVENTARGUMENT"];
11            }

12            if (string.IsNullOrEmpty(requestValue))
13            {
14                foreach (string id in req.Form.AllKeys)
15                {
16                    if (controlId.Equals(GetFriendlyControlId(id), StringComparison.InvariantCultureIgnoreCase))
17                    {
18                        requestValue = req[id];
19                        break;
20                    }

21                }

22            }

23            return requestValue;
24        }

25
26        public static string GetFriendlyControlId(string renderedControlId)
27        {
28            int indexOfSeparator = renderedControlId.LastIndexOf(GetPageIdSeparator());
29            if (indexOfSeparator >= 0)
30            {
31                renderedControlId = renderedControlId.Substring(indexOfSeparator + 1);
32            }

33            return renderedControlId;
34        }

35
36        private static string GetPageIdSeparator()
37        {
38            Page page = HttpContext.Current.CurrentHandler as Page;
39            return page == null ? "$" : page.IdSeparator.ToString();
40        }

41