PostBackTrigger

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,
I'm developing an Ajax enabled Web Site and I've created a Web User Control
(wuc.ascx) with a Button control inside.
There is an main.aspx web page that contains these objects:
- Script Manager
- UpdatePanel2
- Modal Popup Extender
- wuc.ascx user control

wuc.ascx is inside to UpdatePanel2
UpdatePanel2 is inside to the panel of Modal Popup Extender.

I would like to refresh (postback) main.aspx page by clicking the button
inside wuc.ascx (when modal popup is running).
To do this i tried to write this code on Load of main.aspx:

PostBackTrigger pstTrigger=new PostBackTrigger();
//I wrote a property to get button ojbect from user control.
pstTrigger.ControlID = wuc1.button.UniqueID;
UpdatePanel2.Triggers.Add(pstTrigger);

When i try to run web site this error occours:

A control with ID 'ctl00$ContentPlaceHolder1$settimana1$button' could not be
found for the trigger in UpdatePanel 'UpdatePanel2'.

If I add a AsyncPostBackTrigger it works (but the behavour is not the same
and this is not what I want)

Please help me.
Thanks
 
I figured out how to do this,

The trick is to forget the PostBackTrigger, and use the method "RegisterPostBackControl()" from your ScriptManager instance on the page.

Say I had a button in my usercontrol "btnPostback", that I want to cause a full postback.

By default, controls are "Protected" inside pages/usercontrols, so I had to make a property "PostbackButtonInstance" inside my usercontrol that returns the button, e.g.

Public ReadOnly Property PostbackButtonInstance As ImageButton
Get
Return btnPostback
End Get
End Property

Then in the page with the UpdatePanel, I had to make a call like this in page load, assuming my "ScriptManager" had the id "sm"

sm.RegisterPostBackControl(myUserControl.PostbackButtonInstance)

Hope this helps someone with the same problem!

--Michael
 
Back
Top