Hi friends...
am uploading a image file to folder... and as show below am using using a panel with ajax pop up extender.. in that i added the textbox control and fileupload control... but when click the button to upload.. the textbox value will be null... so how i to get rid off this bug...

<asp:UpdatePanel ID="Panel1"  ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
                                                        <ContentTemplate>
                                                            <asp:Panel ID="Panel4" runat="server" Style="cursor: move; background-color: #DDDDDD;
                                                                border: solid 1px Gray; color: Black">
                                                                <table cellpadding="5px" width="100%">
                                                                    <tr>
                                                                        <td>
                                                                            <asp:TextBox ID="TextBoxDocuement" Text=""  Style="padding-right: 3px;" runat="server"></asp:TextBox>
                                                                            <ajaxToolkit:TextBoxWatermarkExtender ID="TextBoxDocuement_TextBoxWatermarkExtender"
                                                                                runat="server" Enabled="True" WatermarkText="Description" WatermarkCssClass="watermarked"
                                                                                TargetControlID="TextBoxDocuement">
                                                                            </ajaxToolkit:TextBoxWatermarkExtender>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="2">
                                                                            <asp:FileUpload ID="FileUpload1" runat="server" />
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Button ID="OkButton" OnClick="OkButton_Click" runat="server" CausesValidation="true"
                                                                                Text="Upload" />
                                                                            <asp:Button ID="CancelButton"  runat="server" Text="Cancel" />
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </asp:Panel>
                                                        </ContentTemplate>
                                                        <Triggers>
                                                            <asp:PostBackTrigger ControlID="OkButton" />
                                                        </Triggers>
                                                    </asp:UpdatePanel>
                                                    <ajaxToolkit:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server" DynamicServicePath=""
                                                        PopupControlID="Panel1" BackgroundCssClass="modalBackground" PopupDragHandleControlID="Panel4"
                                                        Enabled="True" CancelControlID="CancelButton" TargetControlID="LinkButtonDocuementUpload">
                                                    </ajaxToolkit:ModalPopupExtender>


protected void OkButton_Click(object sender, EventArgs e)
    {
        ContentManagementSoap Service = new ContentManagementSoapClient();
        UPloadStudentDocumentRequest request = new UPloadStudentDocumentRequest();
        request.Body = new UPloadStudentDocumentRequestBody();

        bool fileOk = false;
        string path = Server.MapPath("~/Uploaded ImageFiles/") + FileUpload1.FileName;
        if (FileUpload1.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
            string[] allowedExtensions = { ".jpg", ".bmp", ".jpeg", ".gif" };
            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                if (fileExtension == allowedExtensions[i])
                {
                    fileOk = true;
                }
            }
        }
        else
        {
            //exit();
        }

        if (fileOk)
        {
            Panel1.Update();
            if (TextBoxDocuement.Text.Length > 0)
            {
                Images ima = new Images();
                ima.DateCreated = DateTime.Now;
                ima.ImagePath = path;
                ima.ImageName = FileUpload1.FileName;
                FileUpload1.PostedFile.SaveAs(path);

                ima.ImageType = FileUpload1.PostedFile.ContentType;
                ima.ImageDescription = TextBoxDocuement.Text;
                User user = (User)Session["User"];
                ima.UserloginId = user.Id;

                StudentManagement.Student stud = (StudentManagement.Student)Session["Student"];
                request.Body.img = ima;
                request.Body.studentId = stud.StudentId;
                UPloadStudentDocumentResponse response = Service.UPloadStudentDocument(request);

                if (response.Body.UPloadStudentDocumentResult != false)
                {
                    GetDocumentList(stud);
                    LabelerrormsgDocument.Text = "File Uploaded Successfully!!";
                    Panel1.Update();
                    LabelerrormsgDocument.Visible = true;
                    TextBoxDocuement.Text = null;
                    //Panel1.Update();
                    // sanju DocumentDelete.Visible = false;
                    PanelDocumentDisplay.Visible = false;
                }
                else
                {
                    LabelerrormsgDocument.Text = "File Uploaded failed!!";
                    LabelerrormsgDocument.Visible = true;
                    TextBoxDocuement.Text = "";
               
                }
            }
            else
            {
                LabelerrormsgDocument.Text = "File Error!!";
                LabelerrormsgDocument.Visible = true;
                TextBoxDocuement.Text = "";
               
            }
        }

Dani AI

Generated

A frequent root cause here is that the ASP.NET FileUpload control does not work with an asynchronous UpdatePanel postback. If the upload button causes a partial (AJAX) postback the browser will not send the file data, and that same AJAX/DOM interaction can make other inputs appear empty on the server. That explains why 's advice to remove the UpdatePanel fixed the problem and why reported the issue resolved.

Practical options:

  • Remove the UpdatePanel around the popup so the Upload button does a normal full postback (simplest and most reliable).
  • Keep AJAX but make the upload button a PostBackTrigger (forces a full postback for that button), or use an upload control designed for async scenarios (for example, the toolkit's AsyncFileUpload or a client-side FormData/XHR implementation).
  • Check the ModalPopupExtender target: point PopupControlID at the actual popup panel (the inner panel) rather than the UpdatePanel wrapper to avoid odd client-side behavior.
  • Confirm the TextBoxWatermarkExtender is not masking the real input (treat the watermark string as empty on submit).

Quick troubleshooting checklist:

  • Temporarily remove AJAX and confirm FileUpload.HasFile becomes true.
  • Use browser devtools Network/FormData to see what is sent.
  • Ensure controls are inside the server form, not disabled, and have runat=server.

Recommended Answers

All 3 Replies

VinayRok,

Do not use UpdatePanel to upload an image. Try it without using UpdatePanel.

Use code tags.
>How?
- see

[CODE=C#] .... statements....

[/code]

Ya thanks it got solved....

Thanks,

Mark this thread as Solved if you get solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.