如何在按钮单击处理期间显示标签?

发布于 2024-11-15 05:10:34 字数 1186 浏览 1 评论 0原文

当我的按钮单击正在处理时,有什么方法可以显示显示“上传..”的标签?

我正在这样做

protected void btnUpload_Click(object sender, EventArgs e)
{
    lblOutput.Text="uploading..";

    HttpPostedFile postedFile = FileUpload1.PostedFile;
    string ClientFileName, ServerFileName;

    if ((FileUpload1.HasFile && FileUpload1.PostedFile != null) || txtUrl.Text!="")
    {
        try
        {
            HttpPostedFile myFile = FileUpload1.PostedFile;

            if (fileType == "Image")
            {
                if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png" || 
                    fileExt == ".bmp" || fileExt == ".tif")
                {
                    ServerFileName = System.IO.Path.Combine(ServerSavePathI, ClientFileName);
                    string serverPath = Server.MapPath(ServerFileName);
                    FileUpload1.SaveAs(serverPath);
                    dbInsert(fileType, fileName, fileExt, 
                             filePath+fileType+"/"+fileName.Replace(" ",string.Empty)+fileExt, 
                             url);
                }
            }
        }
    }
}

,但它是在我的文件上传后显示的。

我做错了什么,还是有其他方法可以做到这一点?

Is there any way to show label that shows "uploading.." while my button click is processing?

I am doing it in this way

protected void btnUpload_Click(object sender, EventArgs e)
{
    lblOutput.Text="uploading..";

    HttpPostedFile postedFile = FileUpload1.PostedFile;
    string ClientFileName, ServerFileName;

    if ((FileUpload1.HasFile && FileUpload1.PostedFile != null) || txtUrl.Text!="")
    {
        try
        {
            HttpPostedFile myFile = FileUpload1.PostedFile;

            if (fileType == "Image")
            {
                if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png" || 
                    fileExt == ".bmp" || fileExt == ".tif")
                {
                    ServerFileName = System.IO.Path.Combine(ServerSavePathI, ClientFileName);
                    string serverPath = Server.MapPath(ServerFileName);
                    FileUpload1.SaveAs(serverPath);
                    dbInsert(fileType, fileName, fileExt, 
                             filePath+fileType+"/"+fileName.Replace(" ",string.Empty)+fileExt, 
                             url);
                }
            }
        }
    }
}

But it showed after my file has been uploaded already.

Am I doing something wrong, or is there any other way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九公里浅绿 2024-11-22 05:10:34
<script type="text/javascript">
        function showMessage() {
            document.getElementById("<%= lblOutput.ClientID %>").innerHTML = "uploading..";
        }
    </script>

<asp:FileUpload runat="server" ID="FileUpload1" />
    <asp:Button runat="server" ID="btnUpload" Text="Upload" OnClick="btnUpload_Click" OnClientClick="showMessage()" />
    <asp:Label runat="server" ID="lblOutput" />
<script type="text/javascript">
        function showMessage() {
            document.getElementById("<%= lblOutput.ClientID %>").innerHTML = "uploading..";
        }
    </script>

<asp:FileUpload runat="server" ID="FileUpload1" />
    <asp:Button runat="server" ID="btnUpload" Text="Upload" OnClick="btnUpload_Click" OnClientClick="showMessage()" />
    <asp:Label runat="server" ID="lblOutput" />
吐个泡泡 2024-11-22 05:10:34

显示标签文本的优先级低于上传线程。您可以通过使用另一个线程来处理文本更改事件来解决此问题。希望有所帮助。

The priority of showing the lable's text is lower than the upload thread.You can solve this by use another thread to handle the text change event.Hope helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文