Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using master page. In master page i have one Update panel.

In my Asp page i use another update panel. in that i am using Fileupload control.

But while running i cant access the file upload control .
it throw error message as Object Reference not set to instance of an object.

Please help me to solve this problem.

Thanks
Mohan

sample code is below

XML
in master page

<div id="content" class="shell">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

                </asp:ContentPlaceHolder>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

in Aspx page :


<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

   <asp:UpdatePanel ID="RegUpdatePanel" runat="server">
                         <ContentTemplate>

  <asp:FileUpload ID="flUpload" runat="server" Width="148px" />
   <asp:Button ID="btSubmit" Text="Upload"  runat="server" OnClick="btn_UploadClick"  />

</ContentTemplate>
                         <Triggers>
                             <asp:PostBackTrigger ControlID="lnkTemplate" />
                             <asp:AsyncPostBackTrigger ControlID="btSubmit" />
                         </Triggers>
                     </asp:UpdatePanel>
Posted
Updated 23-Apr-13 21:04pm
v2
Comments
PrashantSonewane 24-Apr-13 2:38am    
can you add the code which you have tried and erroring out?
Mohan_V 24-Apr-13 3:05am    
Hi Prashant

I updated the question with code. please check and help me

Thanks
Mohan
V Mohan 24-Apr-13 2:55am    
in master page

<div id="content" class="shell">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">




</div>

in Aspx page :


<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:UpdatePanel ID="RegUpdatePanel" runat="server">
<contenttemplate>

<asp:FileUpload ID="flUpload" runat="server" Width="148px" />
<asp:Button ID="btSubmit" Text="Upload" runat="server" OnClick="btn_UploadClick" />


<Triggers>
<asp:PostBackTrigger ControlID="lnkTemplate" />
<asp:AsyncPostBackTrigger ControlID="btSubmit" />
</Triggers>

Form must be encoded with multipart/form-data if we want to upload the file using fileupload which is there in updatepanel. Change encoded attribute of form with following code in page_load event of page.
C#
Page.Form.Attributes.Add("enctype", "multipart/form-data");


--Amit
 
Share this answer
 
Comments
Mohan_V 24-Apr-13 3:26am    
Thanks Amit.

I added the line.But i cant run the application. it shows error as Element not found.

Please help
_Amy 24-Apr-13 3:31am    
Or try this:
<form id="form1" runat="server" enctype="multipart/form-data">
Mohan_V 24-Apr-13 4:23am    
Hi Amy

i add this code in my form but i am getting same problem.

Please help
Member 12386806 29-Mar-16 6:20am    
if(!isPostBack)
{
Page.Form.Attributes.Add("enctype", "multipart/form-data");
}

add this code in page load
XML
in master page

<div id="content" class="shell">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

                </asp:ContentPlaceHolder>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

in Aspx page :


<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

   <asp:UpdatePanel ID="RegUpdatePanel" runat="server">
                         <ContentTemplate>

  <asp:FileUpload ID="flUpload" runat="server" Width="148px" />
   <asp:Button ID="btSubmit" Text="Upload"  runat="server" OnClick="btn_UploadClick"  />

</ContentTemplate>
                         <Triggers>
                             <asp:PostBackTrigger ControlID="lnkTemplate" />
                             <asp:AsyncPostBackTrigger ControlID="btSubmit" />
                         </Triggers>
                     </asp:UpdatePanel>
 
Share this answer
 
Comments
TrushnaK 24-Apr-13 3:22am    
My 5 to you... for both postback and asyncpostback triggers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900