开发者

Persisting Dynamic Controls Over Postback

开发者 https://www.devze.com 2023-01-18 10:26 出处:网络
I have a datagrid that loads on page_load. In this instance I can\'t load the datagrid in page_init as the results of the datagrid are d开发者_C百科etermined by a checkbox and the checkbox would alw

I have a datagrid that loads on page_load.

In this instance I can't load the datagrid in page_init as the results of the datagrid are d开发者_C百科etermined by a checkbox and the checkbox would always be set to true during page_init thanks to the viewstate not being loaded.

I have an OnItemDataBound event on the datagrid that dynamically creates controls and later on I want to access the value of some of these controls (e.g. a text box)

Of course the problem is I can't access these controls values as they don't persist over a postback. Any idea how I can get round this problem?


You could put the code in Page_Init, and then check the value for the checkbox using the Request.Form collection to see if any change happened. That would be one way as in:

var value = Request.Form[this.chkCheck.UniqueID]; //may be ClientID
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号