tags:

views:

72

answers:

1

I am loading a usercontrol in code-behind as show below

Dim AdjFormctl As UserControl = CType(LoadControl("~/Controls/AdjForm.ascx"), UserControl)
Dim EMPFormType As Type = AdjFormctl.GetType()
Dim EMPPK As PropertyInfo = ABCFormType.GetProperty("employeePK")

AdjFormctl.ID = "ucAdjForm"
EMPPK.SetValue(AdjFormctl, Convert.ToInt32(txtEMPPK.Text), Nothing)
phSettlement.Controls.Add(AdjFormctl)

though it is loading properly. When I hit the submit button that is in the usercontrol it is not going inside the buttonclick event and wiping out the usercontrol from the page.

Please help

A: 

Where did you put this code? If you put in the event handler for submit button, the control will ONLY be generated when the submit button is pressed.

It means that you will only see it in the browser when the page comes back after you pressed the button. The html generated as a result of any other action will not have it.

If you want the control to stay you will have to include this code somewhere else i.e. OnLoad event or PreRender event

mfeingold