Monday, March 26, 2012

Access Updatepanel using masterpage

Hi,

Quick scenario... Simple shop with a masterpage, and thus contentpages. On the masterpage I have an updatepanel which is to act as my basket...

Masterpage:

....

<asp:UpdatePanelID="BasketUpdatePanel"runat="server">

<ContentTemplate>

<asp:TableID="BasketTable"runat="server">

<asp:TableRow>

<asp:TableCell>

<asp:LabelID="BasketHeaderLabel"runat="server"Text="Basket"></asp:Label>

</asp:TableCell>

</asp:TableRow>

<asp:TableRow>

<asp:TableCell>

<asp:Labelrunat="server"Text="0"ID="amountControl"></asp:Label>

</asp:TableCell>

</asp:TableRow>

</asp:Table>

</ContentTemplate>

</asp:UpdatePanel>

.....

On my content page I am dynamically adding items for the shop, and a button to add the item to the basket, this including adding a trigger for each button and adding this to the triggercollection of the updatepanel for my basket..

UpdatePanel basketUpdatePanel = (UpdatePanel)this.Master.FindControl("BasketUpdatePanel");
AsyncPostBackTrigger trigger =newAsyncPostBackTrigger();
trigger.ControlID ="amountControl";
trigger.EventName ="Click";
basketUpdatePanel.Triggers.Add(trigger);

No compilation errors but the following error when the page is rendered:

Control with ID 'amountControl' being registered through RegisterAsyncPostBackControl or RegisterPostBackControl must implement either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler.

Help..

Dannv

dannv:

Control with ID 'amountControl' being registered through RegisterAsyncPostBackControl or RegisterPostBackControl must implement either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler.

This error means, you can add only controls to the triggercollection they are able to rise an event. A label, like in your situation, could'nt rise any event.


You are rigth, and this of course makes perfectly sense...

I changed the controlid to

trigger.ControlID = basketButton.ID;

Which is the button where the event is fired from...

Clicking the botton, now fires a postback, but does not activate my click method.. any obvious suggestions...??


dannv:

Clicking the botton, now fires a postback, but does not activate my click method.. any obvious suggestions...??

you've the click method assigned as the click event to the button eg. OnClick="basketButton_Click" for serverside handling or OnClientClick="JavaScriptFunction()" for clientside JavaScript?


It is set to serverside handling, using the OnClick event...


dannv:

Clicking the botton, now fires a postback, but does not activate my click method..

Not realy sure what you mean. The workflow should be: the UpdatePanel has basketButtons ClickEvent as a trigger. If the basketButton fire his ClickEvent, the UpdatePanel is triggered and initialize a partial page update from his content. So what you mean with:but does not activate my click method ? Is the updatepanel not updating? get you any error? if so, which error you get?


Sorry for wasting your time on the last issue... just retested and now it works...Devil

But thanks for your help and patience

Dann

No comments:

Post a Comment