如何从代码隐藏返回字符串并在网页上显示?

时间:2014-08-05 17:12:19

标签: c# javascript jquery asp.net

在我的HTML中,我有一个fileUpload按钮,您可以在其中选择要上传文件的文件,然后单击pbcUploadBtn后,它会在Validation.CheckWellFormed(...)中进行验证。如果文件很好,验证方法返回空字符串,否则返回文件中第一个错误的字符串。如何使用jQuery或js等在我的页面上显示?

<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 个答案:

答案 0 :(得分:4)

在这种情况下,您不需要使用js。 您可以添加标签并更改其文本属性:

<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
    }
}