473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 10755
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

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

Similar topics

8
by: I am Sam | last post by:
Hi everyone, This problem is making me old. I don't want to get any older. I have a multi-nested repeater control as follows: <asp:Repeater ID="clubRep1" Runat="server">...
3
by: Iain Buchanan | last post by:
Moving this code below from v1.1 to 2.0... am now getting this bug... After I bind a repeater I move the repeater inside the placeholder using controls.add(), but when I do this, all the...
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
0
by: =?Utf-8?B?S29uc3RhbnRpbg==?= | last post by:
I have a need to have a repeater inside update panel control which should update dynamically when "Update" button is clicked. I have repeater inside update panel control which takes custom...
3
by: JacekDr | last post by:
Hello, I've got the following problem: I want to add and remove dynamically controls to UpdatePanel. In my user control I have a button, but when I click it I get AsyncPostback and Event for...
3
by: Nathan Sokalski | last post by:
I have a FileUpload control which is inside an UpdatePanel which is inside a TabPanel. In my code, I use the FileUpload's HasFile and FileContent.Length properties. However, after I select a file,...
0
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two...
2
by: dm3281 | last post by:
Hi all -- I have a strange issue. I have obtained a scripted database and compiled ASP.NET 2.0 application from a sister site that I'm trying to implement locally. I have successfully...
4
by: pechar | last post by:
Hi All, This question has been asked many times and I've checked most of the sites with resolutions. None worked for me. 1) I have a page which is a content page to a Masterpage . 2) I have a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.