Forcing full postback in UpdatePanel
-
Hi, I have basically the following structure set up :
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" ... >
:
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" ... >
</asp:ObjectDataSource>
<asp:ImageButton ID="NewInsertButton" runat="server" OnClick="NewInsertButton_Click" />
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource2" ... >
<InsertItemTemplate>
:
<asp:FileUpload ID="FileUpload1" runat="server" />
:
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="Insert" />
</InsertItemTemplate>
:
</asp:FormView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" ... >
</asp:ObjectDataSource>
</ContentTemplate>
</asp:UpdatePanel>I am aware that a FileUpload requires a full page postback. I read the article http://www.4guysfromrolla.com/articles/090209-1.aspx[^] I tried to install a PostBackTrigger programmatically to get a full postback only on the ImageButton1 control. All other postbacks must be partial. (GridView sorting, paging, ...) In code behind I do :
protected void NewInsertButton_Click(object sender, ImageClickEventArgs e)
{
FormView1.ChangeMode(FormViewMode.Insert);
FormView1.DataBind();
ImageButton InsertButton = FormView1.FindControl("ImageButton1") as ImageButton;
if (InsertButton == null)
throw new NullReferenceException("ImageButton1");
ScriptManager Manager = ScriptManager.GetCurrent(Page);
if (Manager == null)
throw new NullReferenceException("ScriptManager");
Manager.RegisterPostBackControl(InsertButton);
:
}The above code does not seem to install a full postback only for the ImageButton1, so the file upload fails. How can I make this work ?
-
Hi, I have basically the following structure set up :
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" ... >
:
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" ... >
</asp:ObjectDataSource>
<asp:ImageButton ID="NewInsertButton" runat="server" OnClick="NewInsertButton_Click" />
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource2" ... >
<InsertItemTemplate>
:
<asp:FileUpload ID="FileUpload1" runat="server" />
:
<asp:ImageButton ID="ImageButton1" runat="server" CommandName="Insert" />
</InsertItemTemplate>
:
</asp:FormView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" ... >
</asp:ObjectDataSource>
</ContentTemplate>
</asp:UpdatePanel>I am aware that a FileUpload requires a full page postback. I read the article http://www.4guysfromrolla.com/articles/090209-1.aspx[^] I tried to install a PostBackTrigger programmatically to get a full postback only on the ImageButton1 control. All other postbacks must be partial. (GridView sorting, paging, ...) In code behind I do :
protected void NewInsertButton_Click(object sender, ImageClickEventArgs e)
{
FormView1.ChangeMode(FormViewMode.Insert);
FormView1.DataBind();
ImageButton InsertButton = FormView1.FindControl("ImageButton1") as ImageButton;
if (InsertButton == null)
throw new NullReferenceException("ImageButton1");
ScriptManager Manager = ScriptManager.GetCurrent(Page);
if (Manager == null)
throw new NullReferenceException("ScriptManager");
Manager.RegisterPostBackControl(InsertButton);
:
}The above code does not seem to install a full postback only for the ImageButton1, so the file upload fails. How can I make this work ?
Because I can't work with your code as prsented I will give this very simple example of an udatepanel containing a button for update and another button for postback ... Hope it helps .
<%@ Page Language="C#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e){
if (Page.IsPostBack) { myLabel.Text = "posted back"; }
ScriptManager current = ScriptManager.GetCurrent(Page);
if (current != null)
{ current.RegisterPostBackControl(Button2); }
}
protected void Button1_Click(object sender, EventArgs e)
{
DropDownList1.Items.Clear();
String[] ds = {"hi RED","sup RED"};
String[] ds1 = { "hi BLUE", "sup BLUE" };
if (DropDownList2.SelectedValue == "RED")
{ DropDownList1.DataSource = ds;
DropDownList1.DataBind(); }
if (DropDownList2.SelectedValue == "BLUE")
{ DropDownList1.DataSource = ds1;
DropDownList1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<style type="text/css">
#UpdatePanel1 { width:300px; height:100px; } </style>
</head>
<body>
<form id="form1" runat="server">
<div style="padding-top: 10px">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
asp:ListItemRED</asp:ListItem>
asp:ListItemBLUE</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="UpDate" />
<asp:Button ID="Button2" runat="server" Text="PostBack" />
</fieldset>
</ContentTemplate> -
Because I can't work with your code as prsented I will give this very simple example of an udatepanel containing a button for update and another button for postback ... Hope it helps .
<%@ Page Language="C#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e){
if (Page.IsPostBack) { myLabel.Text = "posted back"; }
ScriptManager current = ScriptManager.GetCurrent(Page);
if (current != null)
{ current.RegisterPostBackControl(Button2); }
}
protected void Button1_Click(object sender, EventArgs e)
{
DropDownList1.Items.Clear();
String[] ds = {"hi RED","sup RED"};
String[] ds1 = { "hi BLUE", "sup BLUE" };
if (DropDownList2.SelectedValue == "RED")
{ DropDownList1.DataSource = ds;
DropDownList1.DataBind(); }
if (DropDownList2.SelectedValue == "BLUE")
{ DropDownList1.DataSource = ds1;
DropDownList1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<style type="text/css">
#UpdatePanel1 { width:300px; height:100px; } </style>
</head>
<body>
<form id="form1" runat="server">
<div style="padding-top: 10px">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
asp:ListItemRED</asp:ListItem>
asp:ListItemBLUE</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="UpDate" />
<asp:Button ID="Button2" runat="server" Text="PostBack" />
</fieldset>
</ContentTemplate>Thx for the reply. I appreciate your effort. I tested your code, and yes it works, but in my case I use form views which creates their embedded controls dynamically. I found numerous examples on the net, demonstrating how it has to be done, but I found none which resembles my senario. For one reason or another my code does not function, and I would like to know why.
-
Thx for the reply. I appreciate your effort. I tested your code, and yes it works, but in my case I use form views which creates their embedded controls dynamically. I found numerous examples on the net, demonstrating how it has to be done, but I found none which resembles my senario. For one reason or another my code does not function, and I would like to know why.
If you could present some very brief but complete code that illistates your problem I could easily correct it, but it must be brief and complete.