locked
HtmlInputFile value not being passed back RRS feed

  • Question

  • User-2117647399 posted

    I have added an HtmlInputFile HtmlControl to my .aspx page using a "devicespecific" mobile control as follows:

    <mobile:panel id="pnlAttachment" runat="server">
        <mobile:devicespecific id="dspAttachment" runat="server">
            <choice>
                <contenttemplate>
                    <input id="fleAttachment" type="file" size="60" runat="server">
                </contenttemplate>
            </choice>
        </mobile:devicespecific>
    </mobile:panel>

    I then try to access the value of the HtmlInputFile control in my C# code as follows:

    System.Web.UI.HtmlControls.HtmlInputFile fleAttachment = (System.Web.UI.HtmlControls.HtmlInputFile) pnlAttachment.Controls[0].FindControl("fleAttachment");
    
    if (fleAttachment.Value.Trim() != string.Empty)
    {
        //process attachment
    }

    I have used the same technique to obtain the value entered for a multiline TextBox WebControl object, but for some reason the "Value" property of my HtmlInputFile object is always an empty string, even if a value is set on the client by browsing to a file.

    Does anyone have any idea why the value is not being passed back to the server?

     

     

    Friday, April 6, 2007 9:02 AM

All replies

  • User731069546 posted

    You are right. I just tried this in my VB.NET code and using FindControl, I can not find any HTML controls. FidnControl works fine for other WebControls or Mobile Controls.

    Maybe it got something to do with HTML Controls.

    Friday, April 6, 2007 5:43 PM
  • User-1769650146 posted

     if you don't mind to see from my idea on Language=VB

    On my WebForm

    <INPUT class="txtname" id="txtFilePriceList" style="WIDTH: 480px; HEIGHT: 17px" type="file" size="60" name="txtFilePriceList" runat="server">

    And when I want to get string from txtFilePriceList, so i get it from
    xxx = txtFilePriceList.PostedFile.FileName

    And when i want to get FileName from it i use
    xFileName = System.IO.Path.GetFileName(txtFilePriceList.PostedFile.FileName)

    i hope it helps!

    Friday, April 20, 2007 10:24 AM