I have been through several links but didn't find anything helpful. I know it has been asked several times here.
Here is my frontend code
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload runat="server" ID="fuItemImage" Width="370px" TabIndex="12" />
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
Here is the backend code
if (fuItemImage.HasFile)
{
MyFunction.UploadThisFile(anything)
}
When I upload any image and click on the save button it shows false in FileUpload.HasFile. I am stuck and finding no solution for it.
Any help would be appreciated.
you can try this
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload runat="server" ID="fuItemImage" Width="370px" TabIndex="12" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID = "Button1" />
</Triggers>
</asp:UpdatePanel>
add the button id in triggers to upload the file which will do postback
Related
If i am using update panel then PostedFile not giving file path some error are coming and if update panel are removed the page then excel file successfully upload how to solve
your code should be as shown below
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload runat="server" ID="flFile" />
<asp:Button runat="server" ID="btnSubmit" Text="Upload" OnClick="btnSubmit_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
You need to put postback trigger if you are uploading any files.
A FileUpload inside UpdatePanel won't work. You have to post the whole page. You do this by adding a PostBackTrigger to the button you use for uploading files.
Something like this (see Triggers):
<asp:UpdatePanel ID="upnlMain" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload ID="fileUpload" runat="server" Width="400px" />
<asp:Button ID="btnUploadFiles" runat="server" Text="Upload files" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUploadFiles" />
</Triggers>
</asp:UpdatePanel>
If you have problems with not posting the first time a button is clicked then add this to Page Load event:
Page.Form.Attributes.Add("enctype", "multipart/form-data");
Here is my aspx:
<asp:Panel ID="pnl_updateClinicVisit" runat="server" CssClass="modalPopupClinicVisitEntry2" DefaultButton="bt_editClinicVisit_submit" Style="display:none">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button AutoPostBack="false" UseSubmitBehavior="false" ID="AddMedicationChange" ClientIdMode="Static" runat="server" Text="Add Med Change" OnClick="AddMedicationChange_Click" />
<asp:Panel ID="AddNewMedicationPanel" runat="server">
<asp:TextBox ID="NewDrugName" OnTextChanged="NewDrugName_TextChanged" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="NewDrugNameAutoCompleteExtender"
runat="server"
TargetControlID="NewDrugName"
MinimumPrefixLength="1"
EnableCaching="false"
CompletionSetCount="1"
CompletionInterval="500"
ServiceMethod="GetDrugs">
</asp:AutoCompleteExtender>
<asp:DropDownList OnSelectedIndexChanged="NewDrugChange_SelectedIndexChanged" ID="NewDrugChange" runat="server">
<asp:ListItem>Drug +</asp:ListItem>
<asp:ListItem>Drug -</asp:ListItem>
<asp:ListItem>Dose ↑</asp:ListItem>
<asp:ListItem>Dose ↓</asp:ListItem>
</asp:DropDownList>
<asp:Button AutoPostBack="false" UseSubmitBehavior="false" ID="SubmitMedChange" runat="server" Text="Add to Visit" OnClick="SubmitMedicationChange_Click" />
</asp:Panel>
<asp:ModalPopupExtender ID="updateClinicModalPopupExtender" runat="server" TargetControlID="bt_editClinicVisit_dummy"
PopupControlID="pnl_updateClinicVisit" CancelControlID="bt_editClinicVisit_cancel"
DropShadow="true" BackgroundCssClass="modalBackground" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
For some reason my page is reloading when I click the "AddnewMdication" and "SubmitMedChange" buttons. When I have the AutoPostBack=false UseSubmitBehavior=false, the events fire and then the page reloads. If I don't have these attributes then the page reloads before the events even fire. How do I get AJAX functionality within this modal?
Try setting your Buttons as an AsyncPostBackTrigger. You can do this by adding in the Triggers section and declaring the UpdatePanel as a conditional update.
For example
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddMedicationChange" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="SubmitMedChange" EventName="Click" />
</Triggers>
<ContentTemplate>
<%-- Your code here --%>
</ContentTemplate>
</asp:UpdatePanel>
What this should do is to explicitly declare that those two buttons as being Async.
If this doesn't work, will you please post the relevant code to your two button OnClick events? AddMedicationChange_Click and SubmitMedicationChange_Click
If you try to interact with controls outside of the UpdatePanel in your code-behind during an asyncpostback, odd things can start to happen.
EDITED...
I got an ASP.NET Button inside an UpdatePanel, inside a UserControl.
I want to make the IMAGE visible by CLICKing on the UserControl’s Button (btnSubmit).
Using the following js function I’m able to do it in normal postback mode, but it’s not working in Async mode.
The question is, how can I do this in an Async mode or what’s the best way to do this?
User Control (Categories):
<asp:UpdatePanel ID="upItems" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="btnSubmitPostBack();"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
ASP.NET Page
<script>
function btnSubmitPostBack() {
__doPostBack('<%= btnDoSomething.ClientID %>', '');
}
</script>
<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc1:Categories ID="Categories1" runat="server" CatRootName="Products" />
<asp:Button ID="btnDoSomething" CssClass="hidden" runat="server" Text=" Do Something" OnClick=" btnDoSomething_Click" />
<asp:Image ID="Image1" runat="server" Visible="false" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnDoSomething" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
protected void btnDoSomething_Click(object sender, EventArgs e)
{
Image1.Visible = true;
up.Update();
}
Thanks for your attention and help in advance!
OK here we go :( Just compiled and ran this successfully) and I think that's the right way to do it: ( the key here is to find the other user control and drill inside it for your control to update:
You user control code :
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Categories.ascx.cs" Inherits="WebApplication1.Categories" %>
<asp:UpdatePanel ID="upItems" runat=*emphasized text*"server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
User control code behind:
protected void btnSubmit_Click(object sender, EventArgs e)
{
UpdatePanel ImageUpdatePanel = (UpdatePanel)this.Parent.FindControl("up");
Image _img = (Image)ImageUpdatePanel.FindControl("Image1");
_img.Visible = true;
//Updating UpdatePanel
ImageUpdatePanel.Update();
}
and then your page code
<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc1:Categories ID="Categories1" runat="server" CatRootName="Products" />
<asp:Button ID="btnDoSomething" CssClass="hidden" runat="server" Text=" Do Something"/>
<asp:Image ID="Image1" runat="server" Visible="false" ImageUrl="~/Images/heroAccent.png" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnDoSomething" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
this is 100% working solution, if u need I can send u the code too :)
I am doing research to the Modalpopupextender from the Ajax Toolkit.
This code doesn't work, it doesn't open the pop-up. The only thing what happens when I click on the button is: Refreshing the page.
What am I doing wrong? Also tried this with an Updatepanel... Did 3 hours of research before posting this question, please don't blame it on me...
I also used the Toolkitscriptmanager, but that didn't solve it.
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Button ID="btnTest" runat="server" Text="Button" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnTest" PopupControlID="Panel"></asp:ModalPopupExtender>
<asp:Panel ID="Panel" runat="server">
<h1>Hello World!</h1>
</asp:Panel>
Use PostBackTrigger for the button and then check it out .:)
Example:
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnTest" runat="server" Text="Button" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnTest" PopupControlID="Panel"></asp:ModalPopupExtender>
<asp:Panel ID="Panel" runat="server">
<h1>Hello World!</h1>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnTest"/>
</Triggers>
</asp:UpdatePanel>
I have two update panels at my ajax page. This is first time I'm using updatepanel and I don't know what is wrong. I think only btnFilter's Click event must trigger the second update panel's content but changing combo values (which also hides/unhides btnFilter button) makes second updatepanel change content (at least I see transferred data with firebug & second updatepanel blinks sometimes). Online here.
<asp:UpdatePanel ID="upComparison" runat="server">
<ContentTemplate>
Brand:
<asp:DropDownList ID="ddlBrands" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddlBrands_SelectedIndexChanged"
AppendDataBoundItems="true">
<asp:ListItem Value="" Text="Please select a brand..." />
</asp:DropDownList>
<asp:Panel ID="pModels" runat="server" Visible="false">
Model:
<asp:DropDownList ID="ddlModels" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddlModels_SelectedIndexChanged" />
</asp:Panel>
<asp:Panel ID="pButton" runat="server" Visible="false">
<asp:UpdateProgress ID="upMain" runat="server" DisplayAfter="100">
<ProgressTemplate><img src="/Assets/Images/loader.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Button ID="btnFilter" runat="server" Text="Filter"
OnClick="btnFilter_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upList" runat="server">
<ContentTemplate>
<asp:Repeater ID="rProducts" runat="server">
<ItemTemplate>some code here</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnFilter" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
By default, every UpdatePanel will be refreshed during every asynchronous postback.
To change this behavior, set the UpdateMode property to Conditional.