Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Forcing full postback in UpdatePanel

Forcing full postback in UpdatePanel

Scheduled Pinned Locked Moved ASP.NET
questioncomsysadminalgorithms
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paper67
    wrote on last edited by
    #1

    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 ?

    D 1 Reply Last reply
    0
    • P paper67

      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 ?

      D Offline
      D Offline
      daveyerwin
      wrote on last edited by
      #2

      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>

      P 1 Reply Last reply
      0
      • D daveyerwin

        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>

        P Offline
        P Offline
        paper67
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • P paper67

          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.

          D Offline
          D Offline
          daveyerwin
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups