File upload for Dynamic Data - asp.net

I have the following code
<asp:Content ID="headContent" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true">
<DataControls>
<asp:DataControlReference ControlID="FormView1" />
</DataControls>
</asp:DynamicDataManager>
<h2 class="DDSubHeader">
Edit entry from table
<%= table.DisplayName %></h2>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="List of validation errors" CssClass="DDValidator" />
<asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="FormView1"
Display="None" CssClass="DDValidator" />
<asp:FormView runat="server" ID="FormView1" DataSourceID="DetailsDataSource" DefaultMode="Edit"
OnItemCommand="FormView1_ItemCommand" OnItemUpdated="FormView1_ItemUpdated" RenderOuterTable="false"
OnPageIndexChanging="FormView1_PageIndexChanging">
<EditItemTemplate>
<table id="detailsTable" class="DDDetailsTable" cellpadding="6">
<asp:DynamicEntity runat="server" Mode="Edit" />
<tr class="td">
<td colspan="2">
<asp:LinkButton runat="server" CommandName="Update" Text="Update" />
<asp:LinkButton runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
<br />
</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Label ID="lblMessage" runat="server">
</asp:Label>
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" />
</td>
</tr>
</table>
</EditItemTemplate>
<EmptyDataTemplate>
<div class="DDNoItem">
No such item.</div>
</EmptyDataTemplate>
</asp:FormView>
<asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableUpdate="true" />
<asp:QueryExtender TargetControlID="DetailsDataSource" ID="DetailsQueryExtender"
runat="server">
<asp:DynamicRouteExpression />
</asp:QueryExtender>
</ContentTemplate>
</asp:UpdatePanel>
This file was generate using Dynamic Data. I am trying to add a file upload control in the form but in the code behind I can't acces 'FileUpload1' to see if it contains elements.
How can I do that?
If I make a new form it works but I can't get it out to work in my existing form.
<form id="form1" runat="server"></form>

It's common issue.
You are trying to upload file on ajax request calling upload from update panel.
But you need full postback to upload it using serious FileUpload or look for javascript based file upload controls.

Related

ModalPopupExtender only pops up the UpdatePanel once

The ModalPopupExtender wires the btnCancel button to trigger the a popup an UpdatePanel. The UpdatePanel is a cancel confirmation which contains a Yes button and a No button. After clicking the No button, the panel is closed but the btnCancel no longer trigger the popup when being clicked again. The Yes button works and triggers the server side YesButton_Click event. Here is my code. Thanks for your help.
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
<asp:Button ID="btnCancel" Text="Cancel Task" runat="server" ToolTip="Cancel the displayed task and remove it from Tracker" CausesValidation="false" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnCancel"
PopupControlID="ConfirmationPanel" BackgroundCssClass="modalBackground" />
<asp:UpdatePanel ID="upd_yes_no" runat="server">
<ContentTemplate>
<asp:Panel ID="ConfirmationPanel" runat="server" CssClass="modalPopup" Style="display: none">
<div class="modalPopup-text">
Are you sure you want to cancel this task?<br />
<br />
<asp:Button ID="YesButton" runat="server" Text="Yes" CommandArgument="Yes" OnClick="YesButton_Click" />
<asp:Button ID="NoButton" runat="server" Text="No" CommandArgument="No" />
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
I'm not 100% positive but it appears that Extender and Extended controls must reside in the same UpdatePanel. So if you move your Cancel button and ModalPopupExtender control inside the UpdatePanel, it should work as expected.
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
<asp:UpdatePanel ID="upd_yes_no" runat="server">
<ContentTemplate>
<span id="buttons">
<asp:Button ID="btnUndo" Text="Undo Edit" CommandArgument="undo" runat="server"
OnClick="undo" CausesValidation="false" />
<asp:Button ID="btnNewTask" Text="New Task" CommandArgument="newTask" runat="server"
ToolTip="Unchange current and create new task"
OnClick="NewTask" CausesValidation="false" />
<asp:Button ID="btnCancel" Text="Cancel Task" runat="server"
ToolTip="Cancel the displayed task and remove it from Tracker" CausesValidation="false" />
</span>
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnCancel" PopupControlID="ConfirmationPanel" BackgroundCssClass="modalBackground" />
<asp:Panel ID="ConfirmationPanel" runat="server" CssClass="modalPopup" Style="display: none">
<div class="modalPopup-text">
Are you sure you want to cancel this task?
<br />
<br />
<asp:Button ID="YesButton" runat="server" Text="Yes" CommandArgument="Yes" OnClick="YesButton_Click" />
<asp:Button ID="NoButton" runat="server" Text="No" CommandArgument="No" />
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>

Calender extender not working after removing and then adding ajax toolkit

The below code was working fine and i accidentally deleted ajax toolkit and when i reconfigured it its nit showing calender on clicking over text box.please tell me what to do with it .
moreover i request you to reply soon
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/emp.Master" CodeBehind="empleaveapp.aspx.vb" Inherits="abc.WebForm10" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<head />.
<%--
<head id="Head2" runat="server" />.
--%>
<head />.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label1" runat="server" Text="From"></asp:Label>
<asp:TextBox ID="calefrom" runat="server" CssClass="textbox" Height="16px"
Width="157px"></asp:TextBox>
<cc1:CalendarExtender ID="calefrom_CalendarExtender" runat="server"
Enabled="True" TargetControlID="calefrom" Format="yyyy-MM-dd">
</cc1:CalendarExtender>
<asp:CompareValidator ID="CompareValidator2" runat="server"
ControlToCompare="txttdate" ControlToValidate="calefrom" CssClass="active"
ErrorMessage="Please enter a day after today's date"
Operator="GreaterThan" > </asp:CompareValidator>
<br />
<asp:TextBox ID="txttdate" runat="server" Width="1px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="To"></asp:Label>
<asp:TextBox ID="caleto" runat="server" Height="20px" CssClass="textbox"></asp:TextBox>
<cc1:CalendarExtender ID="caleto_CalendarExtender" runat="server"
Enabled="True" TargetControlID="caleto" Format="yyyy-MM-dd">
</cc1:CalendarExtender>
<asp:CompareValidator ID="CompareValidator1" runat="server" Format="yyyy-MM-dd"
ControlToCompare="calefrom" ControlToValidate="caleto"
ErrorMessage="To date can not be smaller then from date"
Operator="GreaterThanEqual"></asp:CompareValidator>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Reason"></asp:Label>
<asp:TextBox ID="txtreason" runat="server"
CssClass="textbox"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtreason"
ErrorMessage="Reason is must for manager to know better"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Send Request" />
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</asp:Content>
It's your ScriptManager. It should be cc1:ToolkitScriptManager and not asp:ScriptManager. You need the toolkit's scripts for the extenders to work.

Modal Popup Error

I have a DataList that has a link button and I want this link button envoke a modal popup. I've copied the mpe code from another application where it works in a gridview. The error is thrown as soon as page is openned and each time the link button is clicked. The error is thrown in the ScriptResource file: "Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null.
Parameter name: elements". I understand something has null value but not sure what. Page has over a thousand lines so I'll just paste the part I'm working on.
<ItemTemplate>
<tr class="AssetMngnt-trHeaderRow_bgColor">
<td valign="top">
<asp:Label ID="lblIdent" runat="server" Text='<%# Eval("Printer_Ident") %>' Visible="false"></asp:Label>
</td>
<td>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="Select" Text="Edit" />
</td>
<td valign="top" nowrap>
<asp:Label ID="lblName" Text='<%# Eval("Network_Name") %>' runat="server" />
</td>
<td valign="top">
<asp:LinkButton ID="lbPrinterModel"
runat="server" CausesValidation="False" CommandName="Select" CommandArgument="ShowAsset"
Text='<%# Eval("Printer_Mfg") + " " + (string)Eval("Printer_Model") %>' />
</td>
<td valign="top">
<asp:Label ID="lblLocation" Text='<%# Eval("Location") %>' runat="server" />
</td>
<td>
<asp:LinkButton ID="LinkButton1"
runat="server" CausesValidation="False" CommandName="Select" CommandArgument="IssueToners"
Text="Issue Toners" />
<asp:Button runat="server" ID="btnShowPopup" style="display:none" />
<ajaxToolkit:ModalPopupExtender runat="server" id="mpeIssueToners"
TargetControlID="btnShowPopup"
PopupControlID="pnlFvIssueTonersModal"
CancelControlID="UpdateCancelButton"
BackgroundCssClass="modalBackground" >
</ajaxToolkit:ModalPopupExtender>
</td>
</tr>
</ItemTemplate>
<asp:Panel runat="server" ID="pnlFvIssueTonersModal" Visible="true" style="display:none">
<asp:Panel runat="server" ID="pnlFvIssueToners" Visible="true">
<div id="AssetMngnt-FloatLeft_alt"">
<!-- ISSUE TONERS FORM VIEW ******************************************************************************** -->
<asp:FormView ID="fvIssueCartridges" runat="server" DataSourceID="ODSIssueCartridges"
OnItemUpdating="fvIssueCartridges_OnItemUpdating" OnItemUpdated="FormView1_Display_Update_Msg"
EnableViewState="False"
EmptyDataRowStyle-CssClass="AssetMngnt-panelRO" >
<EditItemTemplate>
</EditItemTemplate>
</asp:FormView>
<!-- END ISSUE TONERS FORM VIEW **************************************************************************** -->
</div>
</asp:Panel>
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mdlPopup" runat="server"
TargetControlID="div" PopupControlID="div" CancelControlID="btnNo"
OnCancelScript="cancelClick();" BackgroundCssClass="modalBackground" />
<div id="div" runat="server" align="center" class="confirm" style="display:none">
<asp:Label Text="Form is empty - empty records are not allowed."
ForeColor="#000000" runat="server" ID="Label3" /><br />
<asp:Button ID="btnNo" runat="server" Text="Ok" Width="50px" />
</div>
</asp:Panel>
The ModalPopupExtender1 takes care of things inside the FormView.
Thanks,
Risho

Ajax Update Panel in Nested Listview not working

I have an Ajax update panel inside a nested listview as shown below.
<%# Page Title="LV Ajax" Language="VB" MasterPageFile="~/MasterPages/SimpleMasterPage.master"
AutoEventWireup="false" CodeFile="LV Ajax.aspx.vb" Inherits="LV_Ajax" %>
ListView Ajax
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ListView ID="OuterListView" runat="server" DataSourceID="SqlDataSource1">
<EmptyDataTemplate>
No Data Available.
</EmptyDataTemplate>
<ItemTemplate>
<asp:Label ID="PhotoAlbumIdLabel" runat="server" Text='<%# Eval("PhotoAlbumId") %>'
Visible="false" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListView ID="InnerListView" runat="server" DataSourceID="SqlDataSource2">
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<ItemTemplate>
<br />
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' ToolTip='<%# Eval("ToolTip") %>'
Width="400px" Height="300px" />
<br />
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<asp:DataPager ID="DataPager1" runat="server" PageSize="1">
<Fields>
<asp:NextPreviousPagerField FirstPageText="<<" ShowFirstPageButton="True" ShowNextPageButton="False"
PreviousPageText="&lt&nbsp" ShowPreviousPageButton="True" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField LastPageText=">>" ShowLastPageButton="True" NextPageText="&nbsp&gt"
ShowNextPageButton="True" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</span>
</LayoutTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:RenaissanceConnectionString1 %>"
SelectCommand="SELECT [ToolTip], [ImageUrl], [Description], [PhotoAlbumId], [SortOrder] FROM [Picture] WHERE ([PhotoAlbumId] = #PAId) ORDER BY [SortOrder]">
<SelectParameters>
<asp:ControlParameter ControlID="PhotoAlbumIdLabel" DefaultValue="0" Name="PAId"
PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
</span>
</ItemTemplate>
</asp:ListView>
Unfortunately when I click the datapager buttons although the picture changes correctly, the browser displays the page from the top. If I remove the outer listview it works perfectly keeping its position on the page.
This was working correctly, so if you think the code is correct maybe you could suggest some other changes.
If there is any genius out there who can suggest a solution it would be appreciated.
Many thanks in anticipation.
Maybe if you add ChildrenAsTriggers="true and set UpdateMode to Conditional it will work for you.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
Your <ASP:UpdatePanel> tag is missing its <Triggers> element.
I think that it should be something like
<asp:UpdatePanel ... >
<Triggers>
<AsyncPostBackTrigger ControlID='DataPager1'>
</Triggers>
<ContentTemplate> .....

File Upload is not working

I'm using file upload in my site. I'm uploading word Document(Doc,Docx). Suddenly, it's not working. It is not getting the filename. It is showing empty!!! My Code is as follows:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<table width="100%" align="center">
<tr>
<td style="height: 21px" align="center">
<span class="lbl"></span>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Button ID="btnResumedload" Text="Download Resume" runat="server" BackColor="Maroon"
ForeColor="White" Font-Bold="true" OnClick="btnResumedload_Click" Height="27px"
Width="195px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:Button ID="btnUploadnew" Text="Upload New" runat="server" BackColor="Maroon"
ForeColor="White" Font-Bold="true" OnClick="btnUploadnew_Click" Height="30px"
Width="198px" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Button ID="btnDel" Height="30px" Width="198px" OnClientClick="return confirm('Are you sure?');"
BackColor="Maroon" ForeColor="White" Font-Bold="true" Text="Delete Resume" runat="server"
OnClick="btnDel_Click"></asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="center">
<asp:Label ID="lblmsg" runat="server" Font-Bold="True" ForeColor="Red" Visible="False"
Height="17px" Width="855px"></asp:Label>
</td>
</tr>
<tr>
<td align="center">
<span class="txt">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%--<ajaxToolkit:AsyncFileUpload ID="fpResumenew" runat="server" Visible="false" />--%>
<asp:FileUpload ID="fpResumenew" runat="server" Visible="false" Width="226px" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
</span>
</td>
</tr>
<tr>
<td align="center">
</td>
</tr>
<tr>
<td style="vertical-align: top" align="center">
<%--<asp:Button ID="btnUpload" Font-Bold="true" DisabledText="Processing..." Visible="false"
Text="Upload" BackColor="Maroon" ForeColor="White" runat="server" OnClick="btnUpload_Click" />--%>
<cc1:ClickOnceButton ID="btnUpload" Font-Bold="true" DisabledText="Processing..."
Visible="false" Text="Upload" BackColor="Maroon" ForeColor="White" runat="server"
OnClick="btnUpload_Click" DisableAfterClick="True" />
</td>
</tr>
</table>
protected void btn_Click(object sender, EventArgs e)
{
string strfilename = fp.FileName.ToString();
if (fp.PostedFile.FileName.Trim().Length != 0)
{
binary = new byte[fp.PostedFile.ContentLength];
binary = fp.FileBytes;
doc = fp.FileName;
contenttype = fp.PostedFile.ContentType;
}
}
Just a sample!!!
Nothing works for me.. Problem is that I'm using three more buttons in the same page. The other buttons initializing the file upload control. So, when clicking the upload button, the file name is empty. So, I used another page for uploading the word document. Now, it is working.. !! Anyhow, I need the solution for this!! Anyone give me idea!!
Hai vaishu
FileUpload controls are not compatible with UpdatePanel when they are used to upload files as part of an asynchronous postback.
Just check the AJAX documentation. The FileUpload control is not supported inside an UpdatePanel (http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx):
or
use asp:postbacktrigger instead of asyncpostbacktrigger
<asp:updatepanel runat="server" id="UpdatePanel1">
<contenttemplate>
<asp:FileUpload runat="server" id="FileUpload1" />
<asp:button runat="server" id="ButtonSubmit" text="Postback" />
</contenttemplate>
<triggers>
<asp:postbacktrigger controlid="ButtonSubmit" />
</triggers>
</asp:updatepanel>
or
use ajax for asynchronous file upload:
http://www.asp.net/(S(fu2l2uzphr2u3u45q2dnez55))/ajax/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
The reason that the postback trigger is not working in your case is because the FileUpload Control is set to visible=false. If you use display:none instead, the postback trigger will work.
This works just fine, I finally solved the issue... the ButtonSubmit is reload by the trigger so the page got the info from the control.
<asp:updatepanel runat="server" id="UpdatePanel1">
<contenttemplate>
<asp:FileUpload runat="server" id="FileUpload1" />
<asp:button runat="server" id="ButtonSubmit" text="Postback" />
</contenttemplate>
<triggers>
<asp:postbacktrigger controlid="ButtonSubmit" />
</triggers>
</asp:updatepanel>

Resources