I can't figure out how to programmatically add a GridView
with buttons to an UpdatePanel
.
I can do this with simple controls like buttons and labels, but when I try to add a GridView
with buttons, full Postback()
appears.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected override void OnInit(EventArgs e) { UpdatePanel up1 = new UpdatePanel(); up1.ID = "UpdatePanel1"; Button button1 = new Button(); button1.ID = "Button1"; button1.Text = "Submit"; button1.Click += new EventHandler(Button_Click); Label label1 = new Label(); label1.ID = "Label1"; label1.Text = "A full page postback occurred."; GridView gv1 = new GridView(); </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>UpdatePanel Constructor Example</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button2" runat="server" Text="Button" /> <asp:ScriptManager ID="ScriptManager1" runat="server" /> </div> </form> </body> </html>
So, how do you add a gridview with buttons programmatically to an UpdatePanel
without calling a full Postback()
if the GridView
button is pressed?
Edit: Other things I've tried
void gv1_RowDataBound(object sender, GridViewRowEventArgs e) { AsyncPostBackTrigger t = new AsyncPostBackTrigger(); t.ControlID = e.Row.Cells[0].ClientID; t.EventName = "blah"; up1.Triggers.Add(t); }
source share