Transfer between Page and Web control?
There are test.aspx
page and test.ascx
web user control.
I have a button in test.aspx = btn_test
and above code in my button is :
Dim ct As Control = Page.LoadControl("test.ascx")
Panel1.Controls.Add(ct)
开发者_Python百科There is a dropdownlist with value 1 to 10 in test.aspx
and there is label_test
in test.ascx
I need some code when test.ascx
loading, get dropdownlist.selectedvalue
and show it in label_test
.
Please help me !
There are a number of ways to implement this. One you could try would be to cast the test.ascx web control being loaded like so (replace TestControl with the class name for the control):
Dim ct As TestControl = CType(Page.LoadControl("test.ascx"), TestControl)
And then create a public property in the control which you would use to set the value from the DropDownList.
Dim ct As TestControl = CType(Page.LoadControl("test.ascx"), TestControl)
ct.DropDownListValue = DropDownList.SelectedItem.Value
Panel1.Controls.Add(ct)
This property would then be used to set the labels value (either directly using the set accessor or via a method within the test.ascx control).
精彩评论