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>
Related
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
<Services>
<asp:ServiceReference Path="Machine.asmx" />
</asp:ScriptManager>
<div align="center" style="width:auto" >
<asp:UpdatePanel ID="up1" runat="server" Visible="true" UpdateMode="Conditional">
<ContentTemplate>
<table class="nav-justified" border="1" id="table1">
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Select Search Criteria"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlSearchCriteria" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="ddlSearchCriteria_SelectedIndexChanged" Height="30px" Width="200px">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">All</asp:ListItem>
<asp:ListItem Value="2">Data Center</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr id="trDC" runat="server" visible="false"> <td>
<asp:Label ID="lblRegion" runat="server" Text="Select DataCenter"></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlDC" runat="server" AutoPostBack="false" EnableViewState="true" OnSelectedIndexChanged="ddlDC_SelectedIndexChanged" Height="30px" Width="200px">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">a </asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr id="tr1" runat="server" visible="false" >
<td>
<asp:Label ID="lblOrder" runat="server" Text="Order For SOEID"></asp:Label>
</td>
<td >
<asp:TextBox ID="txtOrderFor" runat="server" Height="20px" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="up1" DisplayAfter="0" DynamicLayout="false">
<ProgressTemplate>
<div style="position:absolute; left:45%;">
<div style="position:relative; left:45%;">
<table border="0" align="center">
<tr>
<td>
<img alt=""src="img/loading.gif" height="50px" width="50px" />
</td>
</tr>
</table>
<center>
Please wait...
</center>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
<asp:UpdatePanel ID="up2" runat="server">
<ContentTemplate>
<asp:Label ID="lblRows" runat="server" Font-Size="Large" Visible="false" ></asp:Label>
<asp:GridView ID="gvDetails" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="3" CssClass="bootstrap dataTables_wrapper" DataKeyNames="Order_Item_Id” EnableViewState="false" HeaderStyle-HorizontalAlign="Left" OnPageIndexChanging="gvDetails_PageIndexChanging" OnRowCommand="gvDetails_RowCommand" OnRowDataBound="gvDetails_RowDataBound" PageSize="15" ShowHeaderWhenEmpty="true" Visible="true" Width="100%">
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkBox1" runat="server" AutoPostBack="true" OnCheckedChanged="Check_Clicked"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Order_Item_Id" HeaderStyle-HorizontalAlign="Left" HeaderText="Order Id" />
</Columns>
</asp:GridView>
</div>
<asp:Button ID="Button4" runat="server" Font-Bold="True" Font-Size="XX-Large" OnClick="Button4_Click" Text="Export To Excel" visible="false" />
<asp:Button ID="Button3" runat="server" Font-Bold="True" Font-Size="XX-Large" OnClick="Button3_Click" Text="Submit" Visible="false" />
<asp:Button ID="Button1" runat="server" Font-Bold="True" Font-Size="XX-Large" OnClick="Button1_Click" Text="Cancel" Visible="false" />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button4" />
<asp:PostBackTrigger ControlID="Button3" />
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
I have two update panel and 1 update progress on my aspx page. My first update panel contains two dropdown, on change of first dropdown, second populates and also there is a submit button in the update panel.
When I use selectedindexchange of dropdown, Autopostback occurs, update progress works but I don't want it to work on that event. It should work only on the submit click.
Second update panel contains the data to be shown on click of submit button.
Also,My update progress is not in any of the update panel, it is in a div between both the update panel.
I have a GridView which charge user data, selecting one lifts the panel through a ModalPopupExtender, this panel has UpdatePanel nested as you can see in the code, pressing the save button closes the Popup, can not find the error. help me with this problem.
Removing the UpdatePanel not let the FileUpload upload the file but no longer the Popup is closed, but I need to upload the file and that the Popup is not closed.
<asp:Panel ID="pDatos" runat="server" BackColor="#E0E0E0">
<table>
<tr>
<td>
<asp:GridView runat="server" ID="gvResultado" AutoGenerateColumns="false"
OnRowCommand="gvResultado_OnRowCommand" DataKeyNames="Id, Estado" >
<Columns>
<asp:ButtonField DataTextField="Id" ItemStyle-ForeColor="Black"
ControlStyle-CssClass="hover" CommandName="gvResultado"
HeaderText="Verificar"/>
<asp:BoundField DataField="Nombre" HeaderText="Nombre" ItemStyle-Width="320px" />
<asp:BoundField DataField="Observaciones" HeaderText="Observaciones" ItemStyle-Width="360px" />
<asp:BoundField DataField="Fecha" HeaderText="Fecha" />
<asp:BoundField DataField="Estado" HeaderText="Estado" ItemStyle-Width="120px" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</asp:Panel>
<asp:HiddenField ID="hfPopup" runat="server" />
<ajax:ModalPopupExtender ID="mpePopup" runat="server" PopupControlID="pPopup"
TargetControlID="hfPopup" BackgroundCssClass="backgroundColor">
</ajax:ModalPopupExtender>
<asp:Panel ID="pPopup" runat="server" BackColor="#CFCFCF" Style="display: none" >
<asp:UpdatePanel ID="upPopup" runat="server">
<ContentTemplate>
<table style="width:740px;" align="center">
<tr>
<td align="center" colspan="2">
<asp:GridView runat="server" ID="gvHistorial" AutoGenerateColumns="false"
OnRowCommand="gvHistorial_RowCommand" DataKeyNames="Descargar" >
<Columns>
<asp:BoundField DataField="Legajo" HeaderText="Legajo" ItemStyle-Width="100"/>
<asp:BoundField DataField="Observaciones" HeaderText="Observaciones" ItemStyle-Width="550" />
<asp:BoundField DataField="Fecha" HeaderText="Fecha" ItemStyle-Width="150"/>
<asp:ButtonField DataTextField="Descargar" HeaderText="Descargar" CommandName="gvHistorial_Descargar" />
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td><!-- --></td>
<td >
<asp:UpdatePanel ID="upArchivo" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload ID="luSeleccione" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="bGuardar" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td><!-- --></td>
<td align="left">
<asp:Button runat="server" ID="btnGuardar" OnClick="btnGuardar_Click"
Text="Guardar" CssClass="Button hover" />
<asp:Button runat="server" ID="btnSalir" OnClick="btnSalir_Click"
Text="Salir" CssClass="Button hover" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
I have placed fileupload and asp button in update panel and update progress bar, now my problem is i am unable to get update progressbar on button click , my code is
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="up1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
<ContentTemplate>
<div class="bodytext" style="height: 480px; width: 830px;">
<table style="width: 600px" align="center">
<tr>
<td class="style2">
<br />
File Attachment
</td>
<td>
<br />
<asp:FileUpload ID="fluattach" runat="server" ClientIDMode="Static" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
</td>
<td>
<span class="art-button-wrapper"><span class="l"></span><span class="r"></span>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="art-button" ClientIDMode="Static"
OnClick="btnSubmit_Click" />
</span>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="up1"
DynamicLayout="true">
<ProgressTemplate>
<div id="progressBackgroundFilter">
</div>
<div id="Progressbar" class="Progressbar" align="center" valign="middle" runat="server">
<asp:Image ID="Image1" Width="75" Height="95" runat="server" ImageUrl="~/images/animation_processing.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
i wrote that code it is working fine but unable to see the progressbar in saving time and send the mail, i can remove the trigger progressbar is wroking in save time but sending mail (fileupload HAS returns the false) so no attachment added, i have working both functionalaties, how it possible
please help me as quick as possible....
thank u
hmk
It seems you messed up your code. Try to keep it simple and then try again:
<asp:UpdateProgress runat="server" id="PageUpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" DynamicLayout="false">
<ProgressTemplate>
Processing Request from Update 1. Please Wait..
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel runat="server" id="UpdatePanel1">
<ContentTemplate>
<asp:Button runat="server" id="UpdateButton" onclick="UpdateButton_Click" text="Update 1" />
</ContentTemplate>
</asp:UpdatePanel>
protected void UpdateButton_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
}
I have a simple 2 tab panel setup with 2 validation groups. My problem is that my buttons fire both validation groups.
<cc1:TabPanel ID="TP2" runat="server" HeaderText="" Enabled="true">
<HeaderTemplate>Loan Main</HeaderTemplate>
<ContentTemplate>
<table cellpadding="3" cellspacing="1">
<tr>
<td style="text-align: right"> Quality:</td>
<td><asp:DropDownList ID="ddlAssignedRep" runat="server" DataSourceID="SqlDataSourceAssignedRep"
ValidationGroup="TP2" DataTextField="CreatedBy" DataValueField="CreatedBySFID"
AppendDataBoundItems="True"> </asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceAssignedRep" runat="server" ConnectionString="<%$ ConnectionStrings:EUCNET00720 %>"
SelectCommand="SELECT distinct [CreatedBySFID], [CreatedBy] FROM [tblRefiActions] WHERE ([RefiPkey] = #RefiPkey) ORDER BY [CreatedBy]">
<SelectParameters>
<asp:QueryStringParameter Name="RefiPkey" QueryStringField="Pkey" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource></td>
</tr>
<tr>
<td style="text-align: right"><asp:Button ID="btnSave" runat="server" ValidationGroup="TP2" Text="Save" /></td>
<td> </td>
</tr>
</table>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Quality measure is required."
ValidationGroup="TP2" ControlToValidate="ddlQuality" Display="None" SetFocusOnError="True"></asp:RequiredFieldValidator>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TP3" runat="server" HeaderText="" Enabled="true">
<HeaderTemplate>Short Payoff</HeaderTemplate>
<ContentTemplate>
<table cellpadding="3" cellspacing="1">
<tr>
<td style="text-align: right"> Amount Short:</td>
<td><asp:TextBox ID="txtShortPayoffAmount" ValidationGroup="TP3" runat="server" Columns="12" MaxLength="12"></asp:TextBox></td>
</tr>
<tr>
<td style="text-align: right"> </td>
<td><asp:Button ID="btnPayoffUpdate" runat="server" Text="Update" ValidationGroup="TP3" /></td>
</tr>
</table>
<br />
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Amount can only contain numbers and a single decimal point." ControlToValidate="txtShortPayoffAmount"
ValidationGroup="TP3" Display="None" SetFocusOnError="True"
ValidationExpression="^(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$"> </asp:RegularExpressionValidator>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" ShowMessageBox="True"
ValidationGroup="TP2" ShowSummary="False" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List"
ValidationGroup="TP3" ShowMessageBox="True" ShowSummary="False" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<cc1:ModalPopupExtender ID="ProgressBarModalPopupExtender" runat="server" BackgroundCssClass="ModalBackground" BehaviorID="ProgressBarModalPopupExtender" TargetControlID="hiddenField1" PopupControlID="Panel1" />
<asp:Panel ID="Panel1" runat="server" Style="display: none; background-color: #C0C0C0;"> <img id="MyImage" src="../Images/Vista_Searching_Bar.gif" alt="" />
<div id="processMessage" style="width: 200px;"> <br />
<br />
Loading...<br />
<br />
</div>
</asp:Panel>
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
<script type="text/javascript">
function StartProgressBar() {
var tp2 = Page_ClientValidate("TP2")
if (tp2 == true) {
var myExtender = $find( ProgressBarModalPopupExtender );
ProgressImg = document.getElementById( MyImage );
setTimeout("ProgressImg.src = ProgressImg.src", 10);
myExtender.show();
return true;
}
}
</script>
I think your validation group names are off. The button and validation summary say the validation group "TabPanel3" "TabPanel1" but your validators say "TP3" and "TP2"
Also you need to make sure that the javascript in your button click is having the ValidationGroup passed in. It looks as though right now it is calling "TP2" no matter which button you click based on your comments below.
Try this for your javascript
function StartProgressBar(ValidationGroup) {
if (Page_ClientValidate(ValidationGroup)) {
//do stuff here on valid
return true;
}
else {
return false;
}
}
Then your button click code should be something like this:
<asp:Button ID="btnSave" OnClientClick="return StartProgressBar('TP2');" runat="server" ValidationGroup="TP2" Text="Save" />
and
<asp:Button ID="btnPayoffUpdate" OnClientClick="return StartProgressBar('TP3');" runat="server" Text="Update" ValidationGroup="TP3" />
Make each click return the value of the validation, that way the click will not continue, because if you return true from that function even if the validation fails I am not sure it will stop since you called the validation manually, I don't know if it will run again. But if you return false it will stop the click, or at least it should.
I have set of link buttons outside update panel but when click any one of them they donot work at all , when i set the postbackUrl they make full postback
my source code:
<asp:Panel ID="pnl_viewImages" runat="server">
<asp:Label ID="lbl_viewImages" runat="server" style="texalign: left"
Text="view images :"></asp:Label>
<br />
<br />
<br />
<table cellpadding="0" cellspacing="0" style="width: 100%" class ="Alternating">
<tr>
<td colspan="5">
<asp:UpdatePanel ID="updatePnl_image" runat="server">
<ContentTemplate>
<asp:ListView ID="lv_showImages" runat="server">
<ItemTemplate>
<asp:Image ID="img_showNewsImage0" runat="server" Height="300px"
ImageUrl='<%# "RetreiveImage.ashx" %>' Width="413px" />
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbtn_first" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_last" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_next" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_previous" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="lbtn_delete" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lbtn_first" runat="server" onclick="lbtn_first_Click">first</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtn_previous" runat="server" onclick="lbtn_first_Click"><<</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtn_next" runat="server" onclick="lbtn_first_Click"
>>></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtn_last" runat="server" onclick="lbtn_first_Click">last</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtn_delete" runat="server" onclick="lbtn_first_Click">delete</asp:LinkButton>
</td>
</tr>
</table>
<br />
i tried to remove the table but in vain it does not work also.
You need to put the LinkButtons in the UpdatePanel or put them in their own UpdatePanel.
You appear to be missing a ScriptManger defined before your update panel such as
<asp:ScriptManager ID="ScriptManager1" runat ="server"></asp:ScriptManager>
I think that is probably causing your problem.
Controls outside of the panel can invoke a partial postback.
Paul