PostBackTrigger

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
 
Joined
Sep 26, 2011
Messages
1
Reaction score
0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top