file upload control in update panel? - asp.net

In my web application, one of my web pages contains an update panel in which I have a text box, a file upload control and a button. When the user selects a file using the file upload control and then clicks the button I am not getting any file from the file upload control. When I place a break point, the file upload control's showing a null value. Can you help me?

It's OK to have the upload control itself inside the UpdatePanel; however, the button you click to start the upload must cause a full postback.
To do this, you could either move the button outside the UpdatePanel, or use <Triggers> to force your button to cause a postback:
<UpdatePanel runat="server">
<ContentTemplate>
...
<asp:Button runat="server" ID="myButton" />
...
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="myButton" />
</Triggers>
</UpdatePanel>

Related

Button not triggering function asp.net

I have a form with only a file upload control and 2 gridviews, for each grid view we have an add button and a save button for the whole page:
So the first button for gridview1 works fine but the other 2 buttons are not even displaying the msgbox inside the function, I tried adding CausesValidation=false but that didn't changed anything.
What could be wrong?
<asp:FileUpload ID="fileup" runat="server" />
<asp:Button runat="server" Text=" + Add" ID="btnGrid2"/>
<asp:Button runat="server" Text="Save" ID="btnSave"/>
Change your code from
<asp:Button runat="server" Text="Save" ID="btnSave"/>
To
<asp:Button runat="server" Text="Save" ID="btnSave" onclick="btnSave_Click"/>
That is happening because you've copied whole event from another page and because of that actual event in aspx page is not generated.
Visual Studio gives facility of generating events automatically.
Just Place a control in your page -> Go to Control's Properties -> Navigate to events. -> Find OnClick and duble click there. It will generate your buttonclick event automatically in aspx.vb code behind file.
Or you can simply put a button in your design page and then by clicking on it will also generate buttonclick event automatically.
Hope it helps.

File Upload in Update Panel within the user control not working?

I need to use file upload in user control. user control exists in update panel .
File upload not working FileUpload HasFile always return false
<asp:UpdatePanel ID="upanel" runat="server">
<ContentTemplate>
<uc3:Assignment ID="assignment" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>

File upload is not working with AsyncPostBackTrigger in ASP.Net

I have one html file upload control to upload the profile picture and I'm using update panel and AsyncPostBackTrigger trigger. If I use PostBackTrigger then uploading of profile image works but If I use AsyncPostBackTrigger then uploading doesn't work.
Below is my code inline:
<asp:UpdatePanel ID="pnlZerkerBasicProfile" runat="server">
<input type="file" id="myFile" name="myFile" class="file_input_hidden" onchange="javascript:FileUploadSubmit();" style="cursor: pointer;" />
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSaveProfilePicture" />
</Triggers>
</asp:UpdatePanel>
Can anyone help?
This is a known issue, a full postback is required for the fileupload control to work within an updatepanel i.e. you can't use a AsyncPostBackTrigger.
Edit: Just saw this is a duplicate of FileUpload Doesn't Work When Nested In UpdatePanel? C#

ASP File Upload control not working within a previously hidden panel

I'm utilizing an ASP file upload control on a web page, and I want it hidden until the user wants to upload a file, so the update panel's visible property is false by default. When the button prompting the file upload is clicked, the upload control shows, and a file can be selected, but when the upload button is clicked, an error shows that the PostedFile property of the upload control show "Object reference not set to an instance of an object", even though a file path is visible in the conrrol. This works if the upload control is never hidden. Here is the source:
<asp:UpdatePanel ID="updUploadTestDoc" runat="server" Visible="false">
<ContentTemplate>
<asp:Panel ID="pnlUploadTestDoc" runat="server" GroupingText="Upload Test
Document">
<asp:Label ID="Label3" runat="server" SkinID="FieldLabel" Text="Select File to Upload : " /> &nbsp
<asp:FileUpload ID="uplUploadFile" runat="server" />
<br />
<br />
<asp:Button ID="btnUpload" runat="server" text="Upload" SkinID="ConfirmButton" /> &nbsp
<asp:Button ID="btnCancelUpload" runat="server" Text="Cancel" SkinID="CancelButton" />
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
I've tried hiding/showing updUploadTestDoc, pnlUploadTestDoc and the upload control itself, all with the same results. The VB code where the error occurs is:
strAttachmentPath = pUploadControl.PostedFile.FileName
I'm using VS 2010, framework 4.0. This is my first post here, so let me know if more info is needed. Thanks.
You can't retain/assign value in FileUpload control. This is because of due to browser security reasons. The file submission is possible only on the first submission to server. You can't retain or assign a value to it.
In an UpdatePanel the same thing happens. An Ajax post submission will happen asynchronously and thus the browser won't retain the file. Read this
And the solution is to keep the fileUpload outside the UpdatePanel.
you cant use asp:fileupload inside update panel, it's kinda of issue in asp file upload ,
so get it out of the update panel and it will work perfectly

how to remove page reload

In my application when we click on add button a Modal PopUp Extender appears in that their are 2 asp button Save and Cancel. When we click on these buttons the page gets reloaded i have to stop it.
Plz help ..
Use Ajax. How you go about this depends wholy on your design. Without Ajax, you need to post the page and have it reload. Ajax still performs the posting of the data, but it's behind the scenes from the user point of view, and you need to write scripts to handle the response.
You can add an UpdatePanel to your aspx-markup and set the buttons as AsyncPostbackTriggers, this will cause only the content of the popup to reload, not the complete page.
The result will look something like this:
<asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" ChildrenAsTriggers="true" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="submitButton" EventName="Click" />
</Triggers>
<ContentTemplate>
<!--popup-->
</ContentTemplate>
</asp:UpdatePanel>

Resources