簡體   English   中英

單擊按鈕時進度條不顯示

[英]Progress bar not displaying when button is clicked

我有一個Fileupload控件,當我單擊上載按鈕時,我只是想顯示一個圖像,即進度條或加載gif圖像。 我通過javascript嘗試過,但無法顯示該圖片。 我希望在文件上傳之前顯示該圖像。

這是我的aspx代碼:

<form id="form1" runat="server">
    <div class="transbox" id="mainbk" runat="server" style="position:absolute; top:0px; left:0px; width: 100%; height: 100%;" >
            <fieldset style="width:51%; margin-left:300px;font-family:'Palatino Linotype';font-size:large">
            <legend style="color:white;font-family:'Palatino Linotype'">Upload Video Files</legend>
                <asp:FileUpload EnableViewState="true" runat="server" ID="UploadImages" style="background-color:white; position:relative; font-family:'Palatino Linotype'; font-size:medium" Width="500px" AllowMultiple="false"/>
                <asp:RequiredFieldValidator ID="reqFile" runat="server" ControlToValidate="UploadImages" ErrorMessage="Select a File" style="color:red;position:absolute"></asp:RequiredFieldValidator><br />
                <asp:Label Text="Description:" runat="server" ID="lbldes" style="font-family:'Palatino Linotype';position:absolute; margin-top:10px; font-size:large;color:white" ></asp:Label>
                <asp:TextBox id="txtdes" runat="server" TextMode="MultiLine" Height="60px" style="margin-top:10px;margin-left:195px;" Width="300px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="txtreq" runat="server" ControlToValidate="txtdes" ErrorMessage="Description Required" style="color:red;position:absolute;margin-top:20px;" ></asp:RequiredFieldValidator><br />

                <asp:Button runat="server" ID="uploadedFile" style="position:relative; font-family:'Palatino Linotype'; font-size:medium; width: 112px; height: 29px;" Text="Upload" UseSubmitBehavior="true" OnClick="uploadedFile_Click"/>
                <asp:image id="loading_img" runat="server" style="Display:none;position:absolute;margin-top:-20px;margin-left:200px;" src="../Images/Other Images/waiting.gif" />
            </fieldset>
     </div>
    </form>

這是我的javascript:

 <script type="text/javascript">
        $('#uploadedFile').click(function () {
            $('#loading_img').show(); // Show image
            return true; // Proceed with postback
        });
    </script>

這是aspx.cs頁面中按鈕uploadFile的單擊事件。

protected void uploadedFile_Click(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
             string fileExt = Path.GetExtension(UploadImages.FileName).ToLower();
             if (fileExt == ".flv" || fileExt == ".avi" || fileExt == ".mp4" || fileExt == ".3gp" || fileExt == ".mov" || fileExt == ".wmv" || fileExt == ".mpg" || fileExt == ".asf" || fileExt == ".swf")
             {
                try
                {

                    filepath = Server.MapPath("~/Videos/" + UploadImages.FileName);
                    UploadImages.PostedFile.SaveAs(filepath);
                    vurl=UploadImages.FileName.ToString();
                    newpath = "Images//Video_Thumbs//" + createvidImage(filepath);
                    al = txtdes.Text.ToString();
                    id += 1;
                    string Insert = "Insert into video (vid,videoname,videourl,vidthumb) values (@id,@alter,@vrl,@IMAGE_PATH)";
                    SqlCommand cmd = new SqlCommand(Insert, con);
                    cmd.Parameters.AddWithValue("@IMAGE_PATH", newpath.ToString());
                    cmd.Parameters.AddWithValue("@id", id);
                    cmd.Parameters.AddWithValue("@alter", al);
                    cmd.Parameters.AddWithValue("@vrl", vurl);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('Video Uploaded!!');", true);

                        txtdes.Text = "";
                    }
                    catch (Exception e1)
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('" + e1.Message.ToString() + "!!');", true);
                    }
                }
                catch (Exception ex)
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('" + ex.Message.ToString() + "!!');", true);
                }
            }
        }
    }

請幫我用javascript或C#做到這一點。

這里的問題是<asp:Button/>標記(以及所有asp標記)在頁面中的呈現方式。 如果右鍵單擊並檢查該元素,您會發現其ID實際上不是'uploadedFile',但可能類似於'ctl00_uploadedFile',因此,您的jQuery選擇器找不到該元素。 我建議以下兩件事之一:

1)檢查頁面,查看實際渲染的元素被命名為什么,然后相應地更新jQuery。

2)使用嵌入式C#代碼段提取ID。 例如,您可以將$('#uploadedFile')替換$('#uploadedFile') $('#' + '<%=uploadedFile.ClientID%>') 其中的<%%>部分將評估為C#,並將ClientID屬性(即在頁面上呈現的id值)插入jQuery選擇器。

編輯:顯然我對<asp:Button/>標記弄錯了,它們使用不變的name屬性而不是id屬性進行渲染。 您想要的uploadFile按鈕選擇器是$('input[name="uploadedFile"]')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM