Wednesday, March 21, 2012

Updatepanel and ObjectDataSource Bug?

I have an issue with the updatepanel. I have a button outside the updatepanel that is supposed to update the data that the gridview is displaying. I am using the typicalAsyncPostBackTrigger to bind to the button, but for some reason, the data is not being updated. I even have a label inside the updatepanel to make sure the updatepanel is updating, but unfortunatley, the gridview's data stays old until I reload the page or sort the gridview.

Is this an UpdatePanel and ObjectDataSource bug? I've seen a Gridview update, but just not when it comes through objectdatasource. Here is an example of my code.

<

asp:ObjectDataSourceID="objPlanInfo"runat="server"SelectMethod="ViewPlanInfo" TypeName="DataLayer" />

<

asp:UpdatePanelID="pnlPlanGrid"runat="server"UpdateMode="conditional">
<ContentTemplate>
<asp:GridViewID="gridPlanInfo"runat="server"AllowPaging="true"AllowSorting="true"DataSourceID="objPlanInfo"></asp:GridView>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
</ContentTemplate><Triggers>
<asp:AsyncPostBackTriggerControlID="btnChangeUserPlan"/>
</Triggers>

</

asp:UpdatePanel>

<asp:ButtonID="btnChangeUserPlan"runat="server"Text="Submit"OnClick="btnChangeUserPlan_Click"/>

Nah,

You mist the EventName in your trigger. Add: EventName="Click"

WS


Nah,

You missed the EventName in your trigger. Add: EventName="Click"

WS


I actually had that in before, it didn't work. I tried it again, same problem. Thanks though, any other suggestiosn?
So has anybody been able to get my example working? An update panel that contains a control that pulls data from an objectdatasource with a trigger from a button on the outside??
hello.

well, it should work without any problems. i do have 1 questions though:

1. are you getting a response form the server (use fiddler to check this)
2. are you using master pages? if so, is the button in the master and the updatepanel in a content page? if this is the case, you need to get the uniqueid of the button instead of its id.

Ah friend! You are what they refer to as the "enlightened one". It was indeed a naming error as both my button and update panel were inside a control that inherited from a master page. I feel like I'm closer, but not quite there yet. I don't know how to give the button's clientID on the front end, so I just attached the triggers on the backend on pageload. Here's the code.

if (!Page.IsPostBack){AsyncPostBackTrigger triggerBtn =new AsyncPostBackTrigger();triggerBtn.ControlID = btn.ID;triggerBtn.EventName ="Click";pnlPlanGrid.Triggers.Add(triggerBtn);}

Now oddly enough, I still have the same issue. I tried attaching triggerBtn.ControlID to the btn.ClientID, but it didn't work properly for some strange reason. Am I missing anything else?


Hm, on second thought, that may not have been the issue, because they're both on the same control and you should be binding to the button's id name right?

back to square oneSleep

No comments:

Post a Comment