Using gridview controls as an asyncPostBackTrigger
September 21, 2009 by: B.HardingAdding an async postback trigger in an aspx page requires you to specify the control ID. The problem is that the control ID is generated dynamically for items in a gridview row. Not to worry you can still use them.
Open the control’s onLoad event and add it there using the control’s Unique ID as the AsyncPostpacktrigger’s ControlID. Done! The unique ID is the instance’s ID as opposed to the ID which is the controls name in the template. ClientID is is similar to the Unique ID except it’s fro the client side.
protected void lbDelete_Load(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
udpError.Triggers.Add(new AsyncPostBackTrigger{ ControlID=btn.UniqueID, EventName=”click”});
}



Your example would be quite valuable if you could give more context – your example is very specific. WHen you stated “Open the control’s onLoad event” you mean the Control contained in the gridview, is this correct?
In your example, lbDelete is a listbox contained in the Gridview you want to update, is this correct?
What I need to do is set a n async postback for a ButtonField in a gridview. There are 2 Gridviews in my Update panel which are side by side, clicking the Buttonfield moves the left item to the right, so I need to update both Gridviews. Any ideas?
lbDelete is a Link Button
This will work for your scenario. Change the column that the button is in to a template column. Then edit the column template. This will give you access to the button control and it’s properties. Add an onLoad event for the button and insert code similar to the above.
Hello from Russia!
Can I quote a post in your blog with the link to you?
Sure
Perfect! Thanks!
Nice. Fixed my problem.
Nice. Fixed my problem.