469,306 Members | 1,916 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Problem with Repeater control in UpdatePanel

126 100+
Hello Guys,

I have been trying to solve the following problem from past 3 days with no luck.

This is what I am trying to do:

I want to allow user (Professor) to choose a course material using "asp:FileUpload" control, upload into the database by clicking "asp:Button" control and allow Professor to view the files he/she uploaded using "asp:Repeater" control.

The procedure is working perfectly fine. But when I place the "asp:Repeater" control in Ajax UpdatePanel, I am unable to retrieve file from "asp:FileUpload" control.

Please help me out. Thanks a million in advance.

1. The following is "CreateSchedule.aspx" page, using this page a professor can upload course materials.

Expand|Select|Wrap|Line Numbers
  1. <asp: Content ID="Content1"  ContentPlaceHolderID="ContentPlaceholder1" Runat="Server">
  2.  
  3. <table>
  4. <tr>
  5. <td>Select File:</td>
  6. <td><asp:FileUpload ID="CMFileUpload" runat="server" /></td>
  7. </tr>
  8. <tr>
  9. <td colspan=2>
  10. <asp:Button ID="CMUploadButton" runtat="server" Text="Upload" onClick="CMUploadButton_Click">
  11. </td>
  12. </tr>
  13. <td>Course Materials Uploaded:</td>
  14. <td>
  15. <asp:ScriptManager ID="ScriptManager1" runat="server">
  16. </asp:ScriptManager>
  17. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditional>
  18. <ContentTemplate>
  19.     <asp:Repeater ID="CMRepeater" runat="server"><ItemTemplate>   
  20.     <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Click" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"File_UID") %>'><%#DataBinder.Eval(Container.DataItem,"File_Name2") %></asp:LinkButton>
  21.     <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/wrong-icon.gif" OnCommand="ImageButton1_Click" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"File_UID") %>' /> 
  22.     </ItemTemplate></asp:Repeater>
  23. </ContentTemplate>
  24. <Triggers>
  25.     <asp:AsyncPostBackTrigger ControlID="CMUploadButton" EventName="Click" />
  26. </Triggers>
  27. </asp:UpdatePanel>
  28. </td>
  29. <tr>
  30. </tr>
  31. </table>
  32. </asp:Content>
2. "CreateSchedule.aspx.cs" page:

Expand|Select|Wrap|Line Numbers
  1. protected void CMUploadButton_Click(object sender, EventArgs e)
  2.     {
  3.         if (!CMFileUpload.HasFile) return;
  4.         int weekNo = 1;
  5.         byte[] binary = new byte[CMFileUpload.PostedFile.ContentLength];
  6.         binary = CMFileUpload.FileBytes;
  7.         SqlParameter param = null;
  8.         SqlConnection conn = new SqlConnection();
  9.         conn.ConnectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=CSMS;Integrated Security=true";
  10.         SqlCommand cmd = new SqlCommand("UploadCourseMaterials", conn);
  11.         cmd.CommandType = CommandType.StoredProcedure;
  12.         param = new SqlParameter("@File_Name1", SqlDbType.NVarChar, 50,
  13.                 ParameterDirection.Input, false, 0, 0, "",
  14.                 DataRowVersion.Default, CMFileUpload.FileName);
  15.         cmd.Parameters.Add(param);
  16.         param = new SqlParameter("@File_Name2", SqlDbType.NVarChar, 50,
  17.                 ParameterDirection.Input, false, 0, 0, "",
  18.                 DataRowVersion.Default, CMNameTextBox.Text);
  19.         cmd.Parameters.Add(param);
  20.         param = new SqlParameter("@File_Content", SqlDbType.Image);
  21.         param.Direction = ParameterDirection.Input;
  22.         param.Value = binary;
  23.         cmd.Parameters.Add(param);
  24.         param = new SqlParameter("@Content_Type", SqlDbType.NVarChar, 50,
  25.                 ParameterDirection.Input, false, 0, 0, "",
  26.                 DataRowVersion.Default, CMFileUpload.PostedFile.ContentType);
  27.         cmd.Parameters.Add(param);
  28.         param = new SqlParameter("@WeekID", SqlDbType.Int, 4);
  29.         param.Value = weekNo;
  30.         cmd.Parameters.Add(param);
  31.  
  32.         conn.Open();
  33.         cmd.ExecuteNonQuery();
  34.         DisplayCourseMaterials();
  35.     }
  36.  
  37. private void DisplayCourseMaterials()
  38.     {
  39.         SqlConnection mySQLconnection = new SqlConnection();
  40.         mySQLconnection.ConnectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=CSMS;Integrated Security=true";
  41.  
  42.         if (mySQLconnection.State == ConnectionState.Closed)
  43.         {
  44.             mySQLconnection.Open();
  45.         }
  46.  
  47.         SqlCommand mySqlSelect = new SqlCommand("select * from CourseMaterials", mySQLconnection);
  48.         mySqlSelect.CommandType = CommandType.Text;
  49.  
  50.         SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
  51.         DataSet myDataSet = new DataSet();
  52.         mySqlAdapter.Fill(myDataSet);
  53.  
  54.         CMRepeater.DataSource = myDataSet;
  55.         CMRepeater.DataBind();
  56.  
  57.         if (mySQLconnection.State == ConnectionState.Open)
  58.         {
  59.             mySQLconnection.Close();
  60.         }
  61.     }
Nov 17 '08 #1
4 10286
Frinavale
9,735 Expert Mod 8TB
The FileUpload control does not work in an UpdatePanel.

Here is a list of controls that do not work within an update panel (according to the Documentation for ASP.NET Ajax Version 1.0
The following ASP.NET controls are not compatible with partial-page updates, and are therefore not supported inside an UpdatePanel control:

TreeView and Menu controls.


FileUpload controls.

GridView and DetailsView controls when their EnableSortingAndPagingCallbacks property is set to true.

Login, PasswordRecovery, ChangePassword, and CreateUserWizard controls whose contents have not been converted to editable templates.


The Substitution control.

Validation controls, which includes the BaseCompareValidator, BaseValidator, CompareValidator, CustomValidator, RangeValidator, RegularExpressionValidator, RequiredFieldValidator, and ValidationSummary control.
Since the FileUpload control requires a full page postback you could consider placing your FileUpload within an IFrame.

-Frinny
Nov 17 '08 #2
JFKJr
126 100+
Hello Frinny,

Thanks for the reply.

I changed the above "CreateSchedule.aspx" page a little bit as follows:

1. "CreateSchedule.aspx" page

Expand|Select|Wrap|Line Numbers
  1. <asp: Content ID="Content1"  ContentPlaceHolderID="ContentPlaceholder1" Runat="Server">  
  2. <table> 
  3. <tr> 
  4. <td>Select File:</td> 
  5. <td>
  6. <asp:ScriptManager ID="ScriptManager1" runat="server"> 
  7. </asp:ScriptManager> 
  8. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditional> 
  9. <ContentTemplate> 
  10.     <asp:FileUpload ID="CMFileUpload" runat="server" />
  11. </ContentTemplate> 
  12. </asp:UpdatePanel> 
  13. </td> 
  14. </tr> 
  15. <tr> 
  16. <td colspan=2> 
  17. <asp:Button ID="CMUploadButton" runtat="server" Text="Upload" onClick="CMUploadButton_Click"> 
  18. </td> 
  19. </tr> 
  20. </table> 
  21. </asp:Content> 
2. "CreateSchedule.aspx.cs" page:

Expand|Select|Wrap|Line Numbers
  1. protected void CMUploadButton_Click(object sender, EventArgs e) 
  2.     { 
  3.          UpdatePanel1.Update();
  4.          if (!CMFileUpload.HasFile) return; 
  5.     }
And whenever I click "Upload" button, it is calling "CMUploadButton_Click" event.

For the first time, the button is unable to retrieve file from "FileUpload" control and coming out of the event procedure (at line #4).

In the following attempts, I am able to retrieve file from "FileUpload" control.

Please kindly let me know how to solve this issue?

Thanks.
Nov 18 '08 #3
Hi all,

Only the solution use AsyncFileUpload instead of asp:fileupload control
Mar 16 '12 #4
Frinavale
9,735 Expert Mod 8TB
Thank you for the reply Muthu.
For those who are unaware of this control, it's part of the free AjaxControlToolkit Library.

-Frinny
Mar 18 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by I am Sam | last post: by
3 posts views Thread by Iain Buchanan | last post: by
5 posts views Thread by Brad Baker | last post: by
reply views Thread by =?Utf-8?B?S29uc3RhbnRpbg==?= | last post: by
reply views Thread by db007 | last post: by
2 posts views Thread by dm3281 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.