?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

?2

?3

?4

?5

?6

?7

?8

?9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
