Hello,
I've got a DataList (Categories) that has a nested GridView (Sub-Categories) in its ItemTemplate. The GridView has a ButtonField (command name = "Select") that, when clicked, I would like to have update an UpdatePanel elsewhere on the page (which will show items within the selected Sub Category). The Sub Categories GridView is created in the ItemDataBound event of the Categories DataList. The problem I'm running into is that when the GridView's SelectedIndexChanged event is fired, the entire page is refreshed instead of just the UpdatePanel.
The UpdatePanel is set up with an UpdateMode of "Conditional" and no triggers are set up declaratively. In the DataList's ItemDataBound event, I'm creating and populating the GridView controls and am setting the UpdatePanel's triggers:
GridView grdItems = (GridView)e.Item.FindControl("grdItems");if (grdItems !=null){ grdItems.DataSource = ; grdItems.DataBind(); AsyncPostBackTrigger trig =new AsyncPostBackTrigger(); trig.ControlID = grdItems.UniqueID.ToString(); trig.EventName ="SelectedIndexChanged"; pnlRight.Triggers.Add(trig);}
Then, in the GridView's SelectedIndexChange event, I query the database and set all of the control values in the UpdatePanel and call the UpdatePanel's Update() method. Is there a piece somewhere that I'm missing that will keep the entire page from posting back? Thanks in advance for your help!
One more thing I noticed: it looks like the first time I click an item in the GridView, the UpdatePanel updates correctly. It's only on subsequent GridView events that the entire page is posted back.
Hi,
Please note that:
Programmatically addingAsyncPostBackTrigger controls is not supported. Use theRegisterAsyncPostBackControl(Control) method of theScriptManager control to programmatically register a postback control, and then call theUpdate() method of theUpdatePanel when the control posts back.
http://asp.net/ajax/documentation/live/mref/T_System_Web_UI_AsyncPostBackTrigger.aspx
Thanks Raymond! By making the changes you mentioned and by calling theRegisterAsyncPostBackControl method in the GridView's init method (instead of the parent control's ItemDataBound method), everything is working like it should!
-Brian
No comments:
Post a Comment