开发者

How to get the value of usercontrol in codebehind of page

How to get the value开发者_如何学Go of usercontrol to page holding usercontrol?


If I understand correctly, the problem is that you are trying to access the user control's StudentId property in page_load of the page that hosts the user control?

If that's the case, it is quite likely that you are just trying to read the data before the user control has fired the SelectedIndexChanged event on the dropdown list.

The simplest solution is to move the code that reads the property to the Page_PreRender event. This event happens late in the page life-cycle, and after all the user events have had a chance to fire off.

As an alternative, you can expose your own event (I'll call it "UserControlDropDownChanged") in the user control and have the code in your SelectedIndexChanged event handler fire the user control's UserControlDropDownChanged event. In your page, during page_load or page_init you'd register an event handler to listen to UserControlDropDownChanged from the user control... and in that event handler perform whatever functions you need to when the drop down list's value changes.

I provided an example of how to use events this way in response to another question here on SO if you aren't familiar with this technique.


You'll need to expose this value as a public property of the user control.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜