从Page_PreInit事件获取DropDownList.SelectedValue [英] Get DropDownList.SelectedValue from Page_PreInit Event

查看:76
本文介绍了从Page_PreInit事件获取DropDownList.SelectedValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回发期间是否可以在Page_PreInit()事件中获取DropDownList.SelectedValue


解决方案

很遗憾我相信答案是否定的。有没有理由在页面初始化之前需要这个

值?


您可以使用JavaScript将值注入cookie中

您的表单的OnSubmit事件,然后使用

HttpContext.Current.Request.Cookies集合读取,以便在回馈后的
上检索您的值。我相信当时已经创建了HttpRequest堆栈,并且在调用页面的OnPreInit方法时,已经从

请求标头构建了这些值。
< br $>
-

Chad Scharf

_______________________________
http://www.chadscharf.com

" Redhairs"写道:


是否有可能在回页期间在Page_PreInit()事件中获取DropDownList.SelectedValue



你好,


为什么使用cookie,使用

string selectedValue =并不容易Request.Form [yourDropDown.UniqueID]



-

Milosz

" Chad Scharf"写道:


不幸的是我相信答案是否定的。有没有理由在页面初始化之前需要这个

值?


您可以使用JavaScript将值注入cookie中

您的表单的OnSubmit事件,然后使用

HttpContext.Current.Request.Cookies集合读取,以便在回馈后的
上检索您的值。我相信当时已经创建了HttpRequest堆栈,并且在调用页面的OnPreInit方法时,已经从

请求标头构建了这些值。
< br $>
-

Chad Scharf

_______________________________
http://www.chadscharf.com


" Redhairs"写道:


是否有可能在回页期间在Page_PreInit()事件中获取DropDownList.SelectedValue



是的,这会更容易。对不起,我通常从不使用Request.Form和

忘了它。


虽然在Page_PreInit事件中可以使用UniqueID,但是看作是

控制树尚未构建,页面难以计算UniqueID,并且通常Control实例将为null

好吧没有?


-

Chad Scharf

_______________________________
http://www.chadscharf.com

" Milosz Skalecki [MCAD]"写道:


你好,


为什么使用cookie,使用
$并不容易b $ b string selectedValue = Request.Form [yourDropDown.UniqueID]




-

Milosz


" Chad Scharf"写道:


不幸的是我相信答案是否定的。有没有理由在页面初始化之前需要这个

值?


您可以使用JavaScript将值注入cookie中

您的表单的OnSubmit事件,然后使用

HttpContext.Current.Request.Cookies集合读取,以便在回馈后的
上检索您的值。我相信当时已经创建了HttpRequest堆栈,并且在调用页面的OnPreInit方法时,已经从

请求标头构建了这些值。
< br $>
-

Chad Scharf

_______________________________
http://www.chadscharf.com

" Redhairs"写道:


是否有可能在回页期间在Page_PreInit()事件中获取DropDownList.SelectedValue



>

>

>


Is it possible to get DropDownList.SelectedValue in Page_PreInit() event
during the postback?

解决方案

Unfortunately I believe the answer is no. Is there a reason you need this
value before the page is initialized?

You could potentially inject the value into a cookie using JavaScript using
the OnSubmit event of your form, then read that using the
HttpContext.Current.Request.Cookies collection to retrieve your value upon
post-back. I believe the HttpRequest stack has been created by then and upon
calling the OnPreInit method of your page, has built these values from the
request headers.

--
Chad Scharf
_______________________________
http://www.chadscharf.com
"Redhairs" wrote:

Is it possible to get DropDownList.SelectedValue in Page_PreInit() event
during the postback?


Howdy,

Why using cookie, wouldn''t be easier just by using
string selectedValue = Request.Form[yourDropDown.UniqueID]
?
--
Milosz
"Chad Scharf" wrote:

Unfortunately I believe the answer is no. Is there a reason you need this
value before the page is initialized?

You could potentially inject the value into a cookie using JavaScript using
the OnSubmit event of your form, then read that using the
HttpContext.Current.Request.Cookies collection to retrieve your value upon
post-back. I believe the HttpRequest stack has been created by then and upon
calling the OnPreInit method of your page, has built these values from the
request headers.

--
Chad Scharf
_______________________________
http://www.chadscharf.com
"Redhairs" wrote:

Is it possible to get DropDownList.SelectedValue in Page_PreInit() event
during the postback?


Yes, that would be easier. Sorry, I typically never use Request.Form and
forgot about it.

Is the UniqueID available though in the Page_PreInit event, seeing as the
control tree has not yet been built, it would be difficult for the Page to
calculate the UniqueID, and typically the Control instance would be null as
well no?

--
Chad Scharf
_______________________________
http://www.chadscharf.com
"Milosz Skalecki [MCAD]" wrote:

Howdy,

Why using cookie, wouldn''t be easier just by using
string selectedValue = Request.Form[yourDropDown.UniqueID]
?
--
Milosz
"Chad Scharf" wrote:

Unfortunately I believe the answer is no. Is there a reason you need this
value before the page is initialized?

You could potentially inject the value into a cookie using JavaScript using
the OnSubmit event of your form, then read that using the
HttpContext.Current.Request.Cookies collection to retrieve your value upon
post-back. I believe the HttpRequest stack has been created by then and upon
calling the OnPreInit method of your page, has built these values from the
request headers.

--
Chad Scharf
_______________________________
http://www.chadscharf.com
"Redhairs" wrote:

Is it possible to get DropDownList.SelectedValue in Page_PreInit() event
during the postback?
>
>
>


这篇关于从Page_PreInit事件获取DropDownList.SelectedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆