开发者

Textbox inside a Repeater inside a Custom Server Control loses values

开发者 https://www.devze.com 2023-02-02 16:31 出处:网络
I am developing my first Custom Server Control which will display a list of fields, with textboxes. When the page containing this custom server control is posted back, the values inside the textbox ar

I am developing my first Custom Server Control which will display a list of fields, with textboxes. When the page containing this custom server control is posted back, the values inside the textbox are lost as the repeater is e开发者_StackOverflowither re-binded, or the viewstate isn't holding onto the values.

How can I get the repeater to hold the values of the textboxes between postbacks?

Cheers!


Most likely you are not re-creating your Custom Control at the right stage of the page lifecycle. Viewstate is restored right after the OnInit() event of the lifecycle. So if you are adding the control after this, the control is not there for the Viewstate to be restored.

Try moving the creation of your dynamic control to the OnInit() event of the page.


If you dynamically populate your repeater? then you might have a timing creation issue based on when View state is loaded.

Try putting all your dynamic control creation into the Page_Init event to preven the timing creation issue.

ie instead of using the Page_Load event use Page_Init event to bind data dinamically in your control.

protected void Page_Init(object sender, EventArgs e){ ..... }

regards, I hope I have been helpful

0

精彩评论

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