Community & Support
Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Ajax > http upload with ajax

Not answered http upload with ajax

Feed from this thread
  • Amanda Intermediate avatar

    Posted on Sep 15, 2008 (permalink)

    Hello, I have the newest version of the Rad Controls and I have a web page with a fileupload on it along with some other form controls.  The user must submit the top part of the page and then the fileupload and a few other controls will then be enabled.  I'm using Ajax for this so the page doesn't look like it refreshes.  When I click the add file button i have to add the file from the FileUpload asp control, it doesn't see anything in the control.  I was wondering how to bypass this.  I've tried this javascript and I can't get it to work. I was wondering if htere's any other ways of making this work?
    1 <script type="text/javascript">  
    2         function OnRequestStart(target, arguments) {  
    3             alert("here");  
    4             if (arguments.EventTarget == "<%# butFile.UniqueID %>") {  
    5                 arguments.EnableAjax = false;  
    6                 alert("Ajax disabled");  
    7             }  
    8         }  
    9 </script> 

    Here's some of my code: (upload file)
    1  Protected Sub butFile_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles butFile.Click  
    2               Dim postedFile As HttpPostedFile = Me.FileUpload1.PostedFile  
    3  
    4         ' Validate   
    5         If Not postedFile Is Nothing AndAlso postedFile.ContentLength > 0 Then 
    6  
    7             ' Retreive the byte data   
    8             Dim b(postedFile.ContentLength - 1) As Byte 
    9             postedFile.InputStream.Read(b, 0, b.Length)  
    10             ' Insert into the database   
    11             Dim sqlConn As SqlConnection = GetSqlConnection()  
    12             Dim sqlComm As New SqlCommand  
    13             ' Configure the command object   
    14             With sqlComm  
    15                 .Connection = sqlConn  
    16                 .CommandType = Data.CommandType.Text  
    17                 Dim ecn As Integer = 201  
    18                 ''''.CommandText = "INSERT INTO [tblFiles]( [fileName], [fileSize], [fileContentType], [fileImage]) VALUES(@fileName, @fileSize, @fileContentType, @fileImage)"  
    19                 .CommandText = "INSERT INTO tblDGdrawings (dg_id, downloadName, length, type, attachment, description, date_added) VALUES ('" & lblid.Text & "', @fileName, @fileSize, @fileContentType, @fileImage, '" & tbDescription.Text & "', '" & Lbldate.Text & "')" 
    20  
    21                 ' Configure the simple parameters   
    22                 'sqlComm.Parameters.Add(New SqlParameter("@fileName", postedFile.FileName))  
    23                 sqlComm.Parameters.Add(New SqlParameter("@fileName", Replace(FileUpload1.PostedFile.FileName, StrReverse(Mid(StrReverse(FileUpload1.PostedFile.FileName), InStr(1, StrReverse(FileUpload1.PostedFile.FileName), "\"))), "")))  
    24  
    25                 sqlComm.Parameters.Add(New SqlParameter("@fileSize", postedFile.ContentLength))  
    26                 sqlComm.Parameters.Add(New SqlParameter("@fileContentType", postedFile.ContentType))  
    27  
    28                 ' Byte data   
    29                 Dim paramBytes As New SqlParameter("@fileImage", Data.SqlDbType.Image, postedFile.ContentLength, "attachment")  
    30                 ' Assign byte value   
    31                 paramBytes.Value = b  
    32                 sqlComm.Parameters.Add(paramBytes)  
    33  
    34                 ' Open the connection and execute   
    35                 sqlConn.Open()  
    36                 sqlComm.ExecuteNonQuery()  
    37  
    38                 ' Cleanup   
    39                 sqlConn.Close()  
    40                 sqlComm.Dispose()  
    41                 sqlComm = Nothing 
    42                 sqlConn.Dispose()  
    43                 sqlConn = Nothing 
    44             End With 
    45  
    46         End If 
    47  
    48         tbDescription.Text = "" 
    49         grdFiles.Rebind()  
    50     End Sub 

    asp code:
    1  <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">  
    2     </telerik:RadStyleSheetManager> 
    3     <p> 
    4         <br /> 
    5         </p> 
    6      
    7     <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"  ClientEvents-OnResponseStart="OnRequestStart">  
    8         <table style="width:50%;">  
    9             <tr> 
    10                 <td colspan="4">  
    11                     <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">  
    12                     </telerik:RadScriptManager> 
    13                     </td> 
    14             </tr> 
    15             <tr> 
    16                 <td> 
    17                     <asp:Label ID="Label1" runat="server" Text="School/Company Name:"></asp:Label> 
    18                     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"   
    19                         ControlToValidate="tbName">*</asp:RequiredFieldValidator> 
    20                     </td> 
    21                 <td> 
    22                     <asp:TextBox ID="tbName" runat="server"></asp:TextBox> 
    23                     </td> 
    24                 <td> 
    25                     <asp:Label ID="Label6" runat="server" Text="Width:"></asp:Label> 
    26                     <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"   
    27                         ControlToValidate="tbWidth" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator> 
    28                     </td> 
    29                 <td> 
    30                     <asp:TextBox ID="tbWidth" runat="server"></asp:TextBox> 
    31                 </td> 
    32             </tr> 
    33             <tr> 
    34                 <td> 
    35                     <asp:Label ID="Label2" runat="server" Text="Dealer:"></asp:Label> 
    36                     <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"   
    37                         ControlToValidate="tbDealer">*</asp:RequiredFieldValidator> 
    38                     </td> 
    39                 <td> 
    40                     <asp:TextBox ID="tbDealer" runat="server"></asp:TextBox> 
    41                     </td> 
    42                 <td> 
    43                     <asp:Label ID="Label7" runat="server" Text="Length:"></asp:Label> 
    44                     <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"   
    45                         ControlToValidate="tbLength" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator> 
    46                     </td> 
    47                 <td> 
    48                     <asp:TextBox ID="tbLength" runat="server"></asp:TextBox> 
    49                 </td> 
    50             </tr> 
    51              <tr> 
    52                 <td> 
    53                     <asp:Label ID="Label3" runat="server" Text="Lab Type:"></asp:Label> 
    54                     </td> 
    55                 <td> 
    56                     <asp:DropDownList ID="ddlLabType" runat="server">  
    57                         <asp:ListItem Value="General">General Lab</asp:ListItem> 
    58                         <asp:ListItem Value="Chem">Chemistry</asp:ListItem> 
    59                         <asp:ListItem>Biology</asp:ListItem> 
    60                         <asp:ListItem>Physics</asp:ListItem> 
    61                         <asp:ListItem Value="Prep">Prep Lab</asp:ListItem> 
    62                         <asp:ListItem>Storage</asp:ListItem> 
    63                         <asp:ListItem Value="Middle">Middle School</asp:ListItem> 
    64                     </asp:DropDownList> 
    65                     </td> 
    66                 <td> 
    67                     <asp:Label ID="Label8" runat="server" Text="Square Feet:"></asp:Label> 
    68                     <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"   
    69                         ControlToValidate="tbSqFeet" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator> 
    70                     </td> 
    71                 <td> 
    72                     <asp:TextBox ID="tbSqFeet" runat="server"></asp:TextBox> 
    73                  </td> 
    74             </tr> 
    75              <tr> 
    76                 <td> 
    77                     <asp:Label ID="Label4" runat="server" Text="Sudent Capacity:"></asp:Label> 
    78                     <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"   
    79                         ControlToValidate="tbStudCap" ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator> 
    80                     </td> 
    81                 <td> 
    82                     <asp:TextBox ID="tbStudCap" runat="server"></asp:TextBox> 
    83                     </td> 
    84                 <td> 
    85                     &nbsp;</td> 
    86                 <td> 
    87                     &nbsp;</td> 
    88             </tr> 
    89              <tr> 
    90                 <td> 
    91                     &nbsp;</td> 
    92                 <td> 
    93                     </td> 
    94                 <td> 
    95                     </td> 
    96                 <td> 
    97                     &nbsp;</td> 
    98             </tr> 
    99              <tr> 
    100                 <td colspan="4">  
    101                     <asp:CheckBoxList ID="cblOptions" runat="server" CellPadding="2"   
    102                         CellSpacing="5" RepeatColumns="4" Width="614px">  
    103                         <asp:ListItem>Perimeter</asp:ListItem> 
    104                         <asp:ListItem>Peninsula</asp:ListItem> 
    105                         <asp:ListItem Value="Octagon Island">Octagon Island</asp:ListItem> 
    106                         <asp:ListItem>Forward Facing Island</asp:ListItem> 
    107                         <asp:ListItem>Rectangular Island</asp:ListItem> 
    108                         <asp:ListItem>Tables</asp:ListItem> 
    109                         <asp:ListItem>B, Open</asp:ListItem> 
    110                         <asp:ListItem>B, Closed</asp:ListItem> 
    111                         <asp:ListItem>B, Drawer</asp:ListItem> 
    112                         <asp:ListItem>B, Combo</asp:ListItem> 
    113                         <asp:ListItem>W, Open</asp:ListItem> 
    114                         <asp:ListItem>W, Closed</asp:ListItem> 
    115                         <asp:ListItem>W, Glass</asp:ListItem> 
    116                         <asp:ListItem>T, Open</asp:ListItem> 
    117                         <asp:ListItem>T, Closed</asp:ListItem> 
    118                         <asp:ListItem>T, Glass</asp:ListItem> 
    119                     </asp:CheckBoxList> 
    120                     </td> 
    121             </tr> 
    122              <tr> 
    123                 <td colspan="4">  
    124                     <asp:Button ID="butSubmit" runat="server" Text="Submit" /> 
    125                     </td> 
    126             </tr> 
    127              </table> 
    128                     
    129             <table> 
    130              <tr> 
    131                 <td> 
    132                     &nbsp;</td> 
    133                 <td> 
    134                     <asp:Button ID="butStartNew" runat="server" Text="Start New Entry"   
    135                         Enabled="False" /> 
    136                  </td> 
    137                 <td> 
    138                     </td> 
    139                 <td> 
    140                     &nbsp;</td> 
    141             </tr> 
    142              
    143              <tr> 
    144                  <td> 
    145                      <asp:Label ID="Label12" runat="server" Font-Bold="True" Text="Add Files"   
    146                          Enabled="False"></asp:Label> 
    147                  </td> 
    148                  <td> 
    149                      &nbsp;</td> 
    150                  <td colspan="2" rowspan="4">  
    151                      <telerik:RadGrid ID="grdFiles" runat="server" AutoGenerateColumns="False"   
    152                          DataSourceID="SqlDataSourceFiles" GridLines="None" Skin="WebBlue">  
    153 <MasterTableView DataSourceID="SqlDataSourceFiles">  
    154 <RowIndicatorColumn Visible="False">  
    155 <HeaderStyle Width="20px"></HeaderStyle> 
    156 </RowIndicatorColumn> 
    157  
    158 <ExpandCollapseColumn Visible="False" Resizable="False">  
    159 <HeaderStyle Width="20px"></HeaderStyle> 
    160 </ExpandCollapseColumn> 
    161  
    162     <Columns> 
    163         <telerik:GridBoundColumn DataField="dg_id" SortExpression="dg_id"   
    164             UniqueName="column" Visible="False">  
    165         </telerik:GridBoundColumn> 
    166         <telerik:GridBoundColumn DataField="id" SortExpression="id"   
    167             UniqueName="column1" Visible="False">  
    168         </telerik:GridBoundColumn> 
    169         <telerik:GridBoundColumn DataField="downloadName" HeaderText="File"   
    170             SortExpression="downloadName" UniqueName="column2">  
    171         </telerik:GridBoundColumn> 
    172         <telerik:GridBoundColumn DataField="description" HeaderText="Description"   
    173             SortExpression="description" UniqueName="column3">  
    174         </telerik:GridBoundColumn> 
    175     </Columns> 
    176  
    177 <EditFormSettings> 
    178 <PopUpSettings ScrollBars="None"></PopUpSettings> 
    179 </EditFormSettings> 
    180 </MasterTableView> 
    181                      </telerik:RadGrid> 
    182                  </td> 
    183             </tr> 
    184              <tr> 
    185                 <td> 
    186                     <asp:Label ID="Label10" runat="server" Text="File:" Enabled="False"></asp:Label> 
    187                     </td> 
    188                 <td> 
    189                     <asp:FileUpload ID="FileUpload1" runat="server" /> 
    190                     </td> 
    191             </tr> 
    192              <tr> 
    193                 <td> 
    194                     <asp:Label ID="Label11" runat="server" Text="File Description:" Enabled="False"></asp:Label> 
    195                     </td> 
    196                 <td> 
    197                     <asp:TextBox ID="tbDescription" runat="server" Width="325px" Enabled="False"></asp:TextBox> 
    198                     </td> 
    199             </tr> 
    200              <tr> 
    201                 <td> 
    202                     <asp:Button ID="butFile" runat="server" Text="Add File" Enabled="False" OnClick="butFile_Click" /> 
    203                     </td> 
    204                 <td> 
    205                     &nbsp;</td> 
    206             </tr> 
    207              <tr> 
    208                 <td> 
    209                     &nbsp;</td> 
    210                 <td> 
    211                     <telerik:RadUpload ID="RadUpload1" Runat="server" Skin="Web20"   
    212                         ControlObjectsVisibility="RemoveButtons, AddButton" /> 
    213                  </td> 
    214                 <td> 
    215                     &nbsp;</td> 
    216                 <td> 
    217                     &nbsp;</td> 
    218             </tr> 
    219              <tr> 
    220                 <td> 
    221                     &nbsp;</td> 
    222                 <td> 
    223                     &nbsp;</td> 
    224                 <td> 
    225                     </td> 
    226                 <td> 
    227                     &nbsp;</td> 
    228             </tr> 
    229         </table> 
    230         </telerik:RadAjaxPanel> 
    231         <asp:SqlDataSource ID="SqlDataSourceFiles" runat="server"   
    232             ConnectionString="<%$ ConnectionStrings:DWJobInfoConnectionString %>"   
    233             SelectCommand="SELECT [dg_id], [id], [downloadName], [description] FROM [tblDGdrawings] WHERE ([dg_id] = @dg_id)">  
    234             <SelectParameters> 
    235                 <asp:ControlParameter ControlID="lblid" Name="dg_id" PropertyName="Text"   
    236                     Type="Int32" /> 
    237             </SelectParameters> 
    238         </asp:SqlDataSource> 
    239     
    240  
    241     <rad:AjaxLoadingPanel ID="AjaxLoadingPanel1" Runat="server" height="16px"   
    242         width="59px">  
    243         <asp:Image runat="server" AlternateText="Loading..."   
    244             ImageUrl="~/RadControls/Ajax/Skins/Default/loading4.gif" /> 
    245     </rad:AjaxLoadingPanel> 
    246         <asp:Label ID="lblid" runat="server" Visible="False"></asp:Label> 
    247         <asp:Label ID="lbldate" runat="server" Visible="False"></asp:Label> 
    248         <br /> 
    Let me know if you need anything else.  Thanks!

    Reply

  • Iana Tsolova Iana Tsolova admin's avatar

    Posted on Sep 17, 2008 (permalink)

    Hi Amanda,

    I followed your scenario in order to replicate the issue but no avail. Please find the attached sample and let me know how it works on your and what differs in your case.

    All the best,
    Iana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
    Attached files

    Reply

  • Amanda Intermediate avatar

    Posted on Sep 22, 2008 (permalink)

    Okay, so I think I figured it out.  When this is called:
    args.EventTarget == "Button1"
    It is button1 but the EventTarget is actually the clientID, so it's actually like this:
    ctl00$ContentPlaceHolder1$Button1
    So, now is turns off the Ajax when that button is clicked.  My problem is that it's running my vb code twice.  So the file is actually being added twice and I only want it once.  How can I change this, do you know?

    Reply

  • Amanda Intermediate avatar

    Posted on Sep 22, 2008 (permalink)

    okay, scratch that!  I was calling the click event twice, so I took it out of the asp on_click event and now it's only running once.  Thanks for your help!

    Reply

  • Q1 Webinar Week

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Ajax > http upload with ajax
Related resources for "http upload with ajax"

ASP.NET Ajax Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]