Wednesday, March 28, 2012

Update trigger in AccordianPane - How to find Control

Hi, I have an accordian with 3 panes. I have buttons and controls in those panes. One of these buttons is used to update an UpdatePanel. I have tried setting theAsyncPostBackTriggerEventName="Click"ControlID="SearchButton", but because the button is in a Accordian it has a different id ID assume.

How can i assign this in the code? What would my findControl() need to be? I get ErrorObject reference not set to an instance of an object.

I have been trying stuff like :

Dim SearchBtnAsNew AsyncPostBackTrigger

SearchBtn.ControlID =Me.FindControl("MyAccordion").FindControl("AccordionPane1").FindControl("SearchButton").ClientID.ToString

MsgBox(Me.FindControl("MyAccordion").FindControl("AccordionPane1").FindControl("SearchButton").ClientID.ToString)

SearchBtn.EventName ="Click"

Me.gridViewUpdate.Triggers.Add(SearchBtn)

You are on the right path, but you are going about it all wrong. You are getting the Error because anytime you use FindControl, you need to cast it to a particular object type:

ProtectedSub Page_PreRender(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.PreRender

Dim SearchButtonAs Button
SearchButton =CType(MyAccordion.FindControl("AccordionPane1").FindControl("Button1"), Button)

Dim TrggrAsNew AsyncPostBackTrigger
Trggr.ControlID = SearchButton.UniqueID'UniqueID, not ClientID.
Trggr.EventName ="Click"
gridViewUpdate.Triggers.Add(Trggr)

EndSub


Yep that sorted it, Thanks a bunch DisturbedBudda

No comments:

Post a Comment