Wednesday, March 28, 2012

Accessing DropDownList in UpdatePanel programmatically

I have an updatepanel within and updatepanel and am trying to access a drop down list as shown below. I am receiving an error saying the object is not set.

Dim LOAN_TYPEAs DropDownList =New DropDownList

LOAN_TYPE = UpdatePanel1.FindControl("UpdatePanel2").FindControl("ddlSIM_TYPE")

If LOAN_TYPE.SelectedValue ="Std"Then 'THIS IS WHERE I RECEIVE MY ERROR

Any ideas?

Try:

Dim LOAN_TYPEAs DropDownList = CType(UpdatePanel1.FindControl("UpdatePanel2").FindControl("ddlSIM_TYPE") , DropDownList)

-Damien


I tried that as well and same message. This is driving me nuts...

Any other ideas? Thanks for your help!


Use UpdatePanel.ContentTemplateContainer.FindControl(), instead.


You are going to hate me but that resulted in the same error message.

UpdatePanel1.ContentTemplateContainer.FindControl("UpdatePanel2").FindControl("ddlSIM_TYPE")


You need to use it on both UpdatePanels. In C#, it would work like this:

UpdatePanel up2 = (UpdatePanel)UpdatePanel1.ContentTemplateContainer.FindControl("UpdatePanel2");
DropDownList ddl = (DropDownList)up2.ContentTemplateContainer.FindControl("ddlSIM_TYPE");

I'm not sure of the exact VB syntax, but hopefully that makes sense.

Though, unless UpdatePanel2 is dynamically generated, you ought to be able to just find the dropdown like this:

DropDownList ddl = (DropDownList)UpdatePanel2.ContentTemplate.FindControl("ddlSIM_TYPE");

Ok, tried that and no luck. Here is the code section:

Dim p2As UpdatePanel = UpdatePanel1.ContentTemplateContainer.FindControl("UpdatePanel2")

Dim PVAs TextBox = p2.ContentTemplateContainer.FindControl("txtSIM_PV")

Dim IAs TextBox = p2.ContentTemplateContainer.FindControl("txtSIM_I")

Dim NAs TextBox = p2.ContentTemplateContainer.FindControl("txtSIM_N")

Dim LOAN_TYPEAs DropDownList = p2.ContentTemplateContainer.FindControl("ddlSIM_TYPE")

If LOAN_TYPE.SelectedValue ="Std"Then

When accessing this if statement i get an object not set error when accessing any of the objects shown above. I have checked and double checked everything and no luck. its inside the Form tag, it has runat=server, etc. Any other ideas - I am at my wits end...

Thanks


Well on the bright side, if you're not getting the error until the conditional, that means the UpdatePanel2 find is working.

Inside UpdatePanel2, are your TextBox and DropDownList controls contained within another control, like a panel or a wizard or a repeater?


Hi,

I agree withgt1329a.

But seeSolution to the FindControl problem for more information about FindControl problem.

Best Regards,

No comments:

Post a Comment