Wrox-Blog: Update Panel Question
Hi,
I am adding more functionality to Wrox blog engine. One of the ideas I had was to let the user upload pictures and manage them and these pictures to be inserted into blogs..
I have an issue related to update panel.. May be I don't fully understand how update panels work or may be I am doing some mistakes without knowing what is going on... I have a panel within an update panel where updatemode set to "conditional" as piece of data in the panel is dynamically updated (drop down list is updated) when something happens in another panel of the web page.This part of the code works fine. But the issue here is within conditional update panel, I have a file upload control. I simply wanted to make sure if user clicks the submit button without having a file selected then prompts an error message to say.. "please select a file to upload:"
If I remove the update panel and test code...it works fine.. I see the error message pops-up.. but as soon as update panel is added & I hit the submit button... following error comes-up..."Object reference not set to an instance of an object"...after searching the web for this error. I thought declaring the file upload control in the code would clear out this error. but it didn't..
Any input would be appreciated
Here is the example code.. ( I clean-up the code..just to isolate the issue and for this posting...)
<asp:UpdatePanel ID="UpdatePanelUserPhotoUpload" runat="server" UpdateMode="Conditional" RenderMode="inline">
<ContentTemplate>
<asp:Panel ID="PanelUserPhotoUpload" runat="server">
<asp:FileUpload ID="Ad_Picture2" runat="server" />
<asp:DropDownList cssClass="dropdown_list_small" skinid="right" AppendDataBoundItems="true" ID="drp_PhotoCategories" runat="server">
</asp:DropDownList>
<asp:Button ID="btn_AddUserPhotos"
ValidationGroup="val_photogroup"
runat="server"
Text="Add User Photo" OnClick="btn_AddUserPhotos_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
================================================== ==
Code:
Protected Sub btn_AddUserPhotos_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Ad_Picture2.PostedFile.ContentLength = 0 Then
ShowPhotoUploadMessage("Please select image to upload")
Exit Sub
End If
End Sub
Last edited by norman001; March 2nd, 2009 at 06:12 PM..
|