0

in my HTML, I have a fileUpload button where you can choose a file to upload a file and then once you click pbcUploadBtn, it goes through validation in Validation.CheckWellFormed(...). The validation method returns an empty string if the file is fine or a string with the first error in the file otherwise. How can I have this display on my page using jQuery or js, etc.?

<div class="upload">
    <asp:FileUpload ID="fileUpload" class="btn" runat="server" />
    <asp:Button ID="pbcUploadBtn" class="btn btn-primary" runat="server" Text="Upload" onclick="uploadBtnClick" />
</div>



protected void uploadBtnClick(object sender, EventArgs e)
{
    if (this.fileUpload.HasFile)
    {
        // file gets uploaded to szSaveToPath
        Validation.CheckWellFormed(szSaveToPath);
        //do things
    }
}
1
  • 1
    Create a label on your page, set visibility on it to false by default. Set the error to that label and change the visibility. Commented Aug 5, 2014 at 17:18

1 Answer 1

4

You don't need to use js in this case. You can add a label and change it's text property:

<div class="upload">
<asp:FileUpload ID="fileUpload" class="btn" runat="server" />
<asp:Button ID="pbcUploadBtn" class="btn btn-primary" runat="server" Text="Upload" onclick="uploadBtnClick" />
<asp:Label runat="server" ID="lblStatus"></asp:Label>

protected void uploadBtnClick(object sender, EventArgs e)
{
    if (this.fileUpload.HasFile)
    {
        // file gets uploaded to szSaveToPath
        lblStatus.Text = Validation.CheckWellFormed(szSaveToPath);
        //do things
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.